diff --git a/parser/parser_query.go b/parser/parser_query.go index 6efe8a6..d981071 100644 --- a/parser/parser_query.go +++ b/parser/parser_query.go @@ -759,7 +759,7 @@ func (p *Parser) parseSelectQuery(_ Pos) (*SelectQuery, error) { case p.tryConsumeKeyword(KeywordUnion) != nil: switch { case p.tryConsumeKeyword(KeywordAll) != nil: - unionAllExpr, err := p.parseSelectStmt(p.Pos()) + unionAllExpr, err := p.parseSelectQuery(p.Pos()) if err != nil { return nil, err } diff --git a/parser/testdata/query/format/select_with_multi_union.sql b/parser/testdata/query/format/select_with_multi_union.sql new file mode 100644 index 0000000..e9d65f6 --- /dev/null +++ b/parser/testdata/query/format/select_with_multi_union.sql @@ -0,0 +1,14 @@ +-- Origin SQL: +SELECT 1 AS v1 UNION ALL SELECT 2 AS v2 UNION ALL SELECT 3 AS v3 + + +-- Format SQL: + +SELECT + 1 AS v1 + UNION ALL +SELECT + 2 AS v2 + UNION ALL +SELECT + 3 AS v3; diff --git a/parser/testdata/query/output/select_with_multi_union.sql.golden.json b/parser/testdata/query/output/select_with_multi_union.sql.golden.json new file mode 100644 index 0000000..0535e66 --- /dev/null +++ b/parser/testdata/query/output/select_with_multi_union.sql.golden.json @@ -0,0 +1,132 @@ +[ + { + "SelectPos": 0, + "StatementEnd": 14, + "With": null, + "Top": null, + "SelectColumns": { + "ListPos": 7, + "ListEnd": 14, + "HasDistinct": false, + "Items": [ + { + "Expr": { + "NumPos": 7, + "NumEnd": 8, + "Literal": "1", + "Base": 10 + }, + "AliasPos": 12, + "Alias": { + "Name": "v1", + "QuoteType": 1, + "NamePos": 12, + "NameEnd": 14 + } + } + ] + }, + "From": null, + "ArrayJoin": null, + "Window": null, + "Prewhere": null, + "Where": null, + "GroupBy": null, + "WithTotal": false, + "Having": null, + "OrderBy": null, + "LimitBy": null, + "Limit": null, + "Settings": null, + "Format": null, + "UnionAll": { + "SelectPos": 25, + "StatementEnd": 39, + "With": null, + "Top": null, + "SelectColumns": { + "ListPos": 32, + "ListEnd": 39, + "HasDistinct": false, + "Items": [ + { + "Expr": { + "NumPos": 32, + "NumEnd": 33, + "Literal": "2", + "Base": 10 + }, + "AliasPos": 37, + "Alias": { + "Name": "v2", + "QuoteType": 1, + "NamePos": 37, + "NameEnd": 39 + } + } + ] + }, + "From": null, + "ArrayJoin": null, + "Window": null, + "Prewhere": null, + "Where": null, + "GroupBy": null, + "WithTotal": false, + "Having": null, + "OrderBy": null, + "LimitBy": null, + "Limit": null, + "Settings": null, + "Format": null, + "UnionAll": { + "SelectPos": 50, + "StatementEnd": 64, + "With": null, + "Top": null, + "SelectColumns": { + "ListPos": 57, + "ListEnd": 64, + "HasDistinct": false, + "Items": [ + { + "Expr": { + "NumPos": 57, + "NumEnd": 58, + "Literal": "3", + "Base": 10 + }, + "AliasPos": 62, + "Alias": { + "Name": "v3", + "QuoteType": 1, + "NamePos": 62, + "NameEnd": 64 + } + } + ] + }, + "From": null, + "ArrayJoin": null, + "Window": null, + "Prewhere": null, + "Where": null, + "GroupBy": null, + "WithTotal": false, + "Having": null, + "OrderBy": null, + "LimitBy": null, + "Limit": null, + "Settings": null, + "Format": null, + "UnionAll": null, + "UnionDistinct": null, + "Except": null + }, + "UnionDistinct": null, + "Except": null + }, + "UnionDistinct": null, + "Except": null + } +] \ No newline at end of file diff --git a/parser/testdata/query/select_with_multi_union.sql b/parser/testdata/query/select_with_multi_union.sql new file mode 100644 index 0000000..85999b4 --- /dev/null +++ b/parser/testdata/query/select_with_multi_union.sql @@ -0,0 +1 @@ +SELECT 1 AS v1 UNION ALL SELECT 2 AS v2 UNION ALL SELECT 3 AS v3