You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ast/formatter: SQL() and pkg/formatter drop IGNORE NULLS, named arguments, ON DUPLICATE KEY UPDATE and INSERT OUTPUT; parser discards SELECT ... SETTINGS #600
The parser stores several constructs that neither ast.SQL() nor pkg/formatter renders, so the output silently changes meaning. ClickHouse SELECT ... SETTINGS is worse: the parser accepts it but has no AST field to store it in.
Reproduction
On main 61ca6c8, tree.SQL(), formatter.FormatAST(tree, ast.CompactStyle()) and ReadableStyle() all give the same result:
Input (dialect)
Output
Stored in AST?
SELECT FIRST_VALUE(x) IGNORE NULLS OVER (ORDER BY y) FROM t
... FIRST_VALUE(x) OVER (ORDER BY y) ...
yes, FunctionCall.NullTreatment = "IGNORE NULLS"
SELECT f(x => 1) FROM t
SELECT f(x) FROM t
yes, arg is *ast.NamedArgument
INSERT INTO t (a) VALUES (1) ON DUPLICATE KEY UPDATE a = 2 (mysql)
INSERT INTO t (a) VALUES (1)
yes, InsertStatement.OnDuplicateKey != nil
INSERT INTO t (a) OUTPUT INSERTED.id VALUES (1) (sqlserver)
INSERT INTO t (a) VALUES (1)
yes, len(InsertStatement.Output) == 1
SELECT a FROM t SETTINGS max_threads = 4 (clickhouse)
SELECT a FROM t
no, SelectStatement has no Settings field
Expected: each clause is kept. For contrast, PostgreSQL ON CONFLICT ... RETURNING round-trips correctly through pkg/formatter.
Notes
pkg/sql/ast/sql.go has no rendering for NamedArgument or FunctionCall.NullTreatment (neither appears in sql.go or pkg/formatter/render.go). The InsertStatement renderers ignore OnDuplicateKey and Output (fields at pkg/sql/ast/ast_statements.go:252,257).
For SETTINGS, the parser should store the assignments on SelectStatement, as it already does for the ClickHouse DDL SETTINGS in pkg/sql/parser/ddl.go:406, and the renderers should emit them.
Add round-trip tests (parse, then SQL()/FormatAST, then re-parse, then compare) for each case.
Activity
fix(ast,formatter): render table-function call arguments in FROM (#607)
fix(parser,ast): ClickHouse parametric aggregates, FROM table functio…
fix(ast,formatter,parser): keep IGNORE NULLS, named arguments, ON DUP…
fix(parser): address review for #600
fix(cli): render gosqlx format through pkg/formatter and refuse non-r…
fix(cli): render gosqlx format through pkg/formatter and refuse non-r…
fix(cli): render gosqlx format through pkg/formatter and refuse non-r…