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)
| 87 | // |
| 88 | // Returns ErrUnsupportedStatement for non-SELECT statements. |
| 89 | func 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 |