MCPcopy
hub / github.com/sqldef/sqldef / normalizeViewColumnsFromDefinition

Function normalizeViewColumnsFromDefinition

schema/normalize.go:1521–1539  ·  view source on GitHub ↗

normalizeViewColumnsFromDefinition extracts and normalizes column names from a view definition. This handles differences in how PostgreSQL versions format column names: - PostgreSQL 13-15: includes table qualifiers (e.g., "users.id") - PostgreSQL 16+: omits unnecessary qualifiers (e.g., "id")

(def parser.SelectStatement, mode GeneratorMode)

Source from the content-addressed store, hash-verified

1519// - PostgreSQL 13-15: includes table qualifiers (e.g., "users.id")
1520// - PostgreSQL 16+: omits unnecessary qualifiers (e.g., "id")
1521func normalizeViewColumnsFromDefinition(def parser.SelectStatement, mode GeneratorMode) []string {
1522 if def == nil {
1523 return nil
1524 }
1525
1526 var selectExprs parser.SelectExprs
1527 switch stmt := def.(type) {
1528 case *parser.Select:
1529 selectExprs = stmt.SelectExprs
1530 default:
1531 // For other statement types (e.g., UNION), we can't easily extract columns
1532 return nil
1533 }
1534
1535 return util.TransformSlice(selectExprs, func(expr parser.SelectExpr) string {
1536 normalized := normalizeSelectExpr(expr, mode)
1537 return strings.ToLower(parser.String(normalized))
1538 })
1539}
1540
1541// normalizeOperator converts operator to lowercase and applies PostgreSQL-specific mappings.
1542// PostgreSQL stores certain operators in a canonical form:

Callers 1

Calls 3

TransformSliceFunction · 0.92
StringFunction · 0.92
normalizeSelectExprFunction · 0.85

Tested by

no test coverage detected