MCPcopy
hub / github.com/sqldef/sqldef / normalizeCheckExprString

Method normalizeCheckExprString

schema/generator.go:5070–5083  ·  view source on GitHub ↗

normalizeCheckExprString returns a normalized string representation of a CHECK constraint expression For PostgreSQL, this converts IN (a,b,c) to = ANY (ARRAY[a,b,c])

(expr parser.Expr)

Source from the content-addressed store, hash-verified

5068// normalizeCheckExprString returns a normalized string representation of a CHECK constraint expression
5069// For PostgreSQL, this converts IN (a,b,c) to = ANY (ARRAY[a,b,c])
5070func (g *Generator) normalizeCheckExprString(expr parser.Expr) string {
5071 if g.mode == GeneratorModePostgres {
5072 normalized := normalizeCheckExpr(expr, g.mode)
5073 // Unwrap outermost parentheses for consistent output (comparison does this too)
5074 normalized = unwrapOutermostParenExpr(normalized)
5075 // In quote-aware mode, use formatExprQuoteAware to preserve quoting in column names
5076 // In legacy mode, use parser.String for backward compatibility (no quoting in expressions)
5077 if !g.config.LegacyIgnoreQuotes {
5078 return g.formatExprQuoteAware(normalized)
5079 }
5080 return parser.String(normalized)
5081 }
5082 return parser.String(expr)
5083}
5084
5085// formatExprQuoteAware formats an expression with quote-aware column name handling.
5086// This walks the AST and uses escapeSQLIdent for column names to preserve quoting.

Callers 2

Calls 4

formatExprQuoteAwareMethod · 0.95
StringFunction · 0.92
normalizeCheckExprFunction · 0.85
unwrapOutermostParenExprFunction · 0.85

Tested by

no test coverage detected