MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / ReplaceColumn

Function ReplaceColumn

pkg/transform/columns.go:89–102  ·  view source on GitHub ↗

ReplaceColumn returns a Rule that replaces every column in the SELECT list that matches oldName with a bare *ast.Identifier for newName. Matching is case-insensitive against both identifier names and aliases. Parameters: - oldName: Name or alias of the column to replace - newName: Replacement ident

(oldName, newName string)

Source from the content-addressed store, hash-verified

87//
88// Returns ErrUnsupportedStatement for non-SELECT statements.
89func ReplaceColumn(oldName, newName string) Rule {
90 return RuleFunc(func(stmt ast.Statement) error {
91 sel, err := getSelect(stmt, "ReplaceColumn")
92 if err != nil {
93 return err
94 }
95 for i, col := range sel.Columns {
96 if columnMatches(col, oldName) {
97 sel.Columns[i] = &ast.Identifier{Name: newName}
98 }
99 }
100 return nil
101 })
102}
103
104// AddSelectStar returns a Rule that appends a wildcard * column to the SELECT list
105// of a SELECT statement. This is a convenience wrapper around AddColumn with an

Callers 1

TestReplaceColumnFunction · 0.85

Calls 3

RuleFuncFuncType · 0.85
getSelectFunction · 0.85
columnMatchesFunction · 0.85

Tested by 1

TestReplaceColumnFunction · 0.68