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: NOT EXISTS (subquery) renders as NOT (EXISTS (...) NOT ), which does not re-parse #601
The parser represents NOT EXISTS (subquery) as a BinaryExpression{Operator: "NOT", Not: true, Left: ExistsExpression, Right: nil}. BinaryExpression.writeSQL has no case for this unary-NOT shape. It falls into the generic Not branch and emits NOT (<left> NOT <nil>). ast.SQL(), pkg/formatter (compact and readable) and formatter.FormatString therefore all produce SQL that fails to parse.
Reproduction
tree, _:=gosqlx.Parse("SELECT * FROM t WHERE NOT EXISTS (SELECT 1 FROM u)")
fmt.Println(tree.SQL())
fmt.Println(formatter.FormatAST(tree, ast.CompactStyle()))
SELECT * FROM t WHERE NOT (EXISTS (SELECT 1 FROM u) NOT )
Re-parsing fails with Error E2002 at line 1, column 53: expected ), got NOT. formatter.FormatString gives SELECT *\nFROM t\nWHERE NOT (EXISTS (SELECT 1 FROM u) NOT );, which fails the same way. The same happens inside larger predicates (... NOT EXISTS (...) AND a = 1).
Expected: SELECT * FROM t WHERE NOT EXISTS (SELECT 1 FROM u).
Notes
pkg/sql/ast/sql.go:313 (BinaryExpression.writeSQL): the if b.Not block at ~line 347 writes NOT ( Left op Right ) with no nil-Right guard. Add a branch for Right == nil (operator NOT) that writes NOT followed by Left. pkg/formatter reaches this code through exprSQL and SQL(), so the one fix covers both.
Activity
fix(cli): render gosqlx format through pkg/formatter and refuse non-r…
fix(ast): render NOT EXISTS as a prefix NOT so SQL() and formatter ou…
fix(ast): render NOT EXISTS as a prefix NOT so SQL() and formatter ou…
fix(cli): render gosqlx format through pkg/formatter and refuse non-r…
test(cli): drop corpus known-gap entries fixed by #601
fix(cli): require MySQL output to keep the input's double-quoted tokens
fix(cli): render gosqlx format through pkg/formatter and refuse non-r…