Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions parser/parser_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ func (p *Parser) parseSelectQuery(_ Pos) (*SelectQuery, error) {
}
selectStmt.UnionAll = unionAllExpr
case p.tryConsumeKeywords(KeywordDistinct):
unionDistinctExpr, err := p.parseSelectStmt(p.Pos())
unionDistinctExpr, err := p.parseSelectQuery(p.Pos())
if err != nil {
return nil, err
}
Expand All @@ -811,7 +811,7 @@ func (p *Parser) parseSelectQuery(_ Pos) (*SelectQuery, error) {
return nil, fmt.Errorf("expected ALL or DISTINCT, got %s", p.lastTokenKind())
}
case p.tryConsumeKeywords(KeywordExcept):
exceptExpr, err := p.parseSelectStmt(p.Pos())
exceptExpr, err := p.parseSelectQuery(p.Pos())
if err != nil {
return nil, err
}
Expand Down
5 changes: 5 additions & 0 deletions parser/testdata/query/format/select_with_multi_except.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- Origin SQL:
SELECT number FROM numbers(1, 10) EXCEPT SELECT number FROM numbers(3, 6) EXCEPT SELECT number FROM numbers(8, 9)

-- Format SQL:
SELECT number FROM numbers(1, 10) EXCEPT SELECT number FROM numbers(3, 6) EXCEPT SELECT number FROM numbers(8, 9);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- Origin SQL:
SELECT 1 AS v1 UNION DISTINCT SELECT 2 AS v2 UNION DISTINCT SELECT 3 AS v3

-- Format SQL:
SELECT 1 AS v1 UNION DISTINCT SELECT 2 AS v2 UNION DISTINCT SELECT 3 AS v3;
222 changes: 222 additions & 0 deletions parser/testdata/query/output/select_with_multi_except.sql.golden.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
[
{
"SelectPos": 0,
"StatementEnd": 32,
"With": null,
"Top": null,
"HasDistinct": false,
"SelectItems": [
{
"Expr": {
"Name": "number",
"QuoteType": 1,
"NamePos": 7,
"NameEnd": 13
},
"Modifiers": [],
"Alias": null
}
],
"From": {
"FromPos": 14,
"Expr": {
"Table": {
"TablePos": 19,
"TableEnd": 32,
"Alias": null,
"Expr": {
"Name": {
"Name": "numbers",
"QuoteType": 1,
"NamePos": 19,
"NameEnd": 26
},
"Args": {
"LeftParenPos": 26,
"RightParenPos": 32,
"Args": [
{
"NumPos": 27,
"NumEnd": 28,
"Literal": "1",
"Base": 10
},
{
"NumPos": 30,
"NumEnd": 32,
"Literal": "10",
"Base": 10
}
]
}
},
"HasFinal": false
},
"StatementEnd": 32,
"SampleRatio": null,
"HasFinal": false
}
},
"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": {
"SelectPos": 41,
"StatementEnd": 72,
"With": null,
"Top": null,
"HasDistinct": false,
"SelectItems": [
{
"Expr": {
"Name": "number",
"QuoteType": 1,
"NamePos": 48,
"NameEnd": 54
},
"Modifiers": [],
"Alias": null
}
],
"From": {
"FromPos": 55,
"Expr": {
"Table": {
"TablePos": 60,
"TableEnd": 72,
"Alias": null,
"Expr": {
"Name": {
"Name": "numbers",
"QuoteType": 1,
"NamePos": 60,
"NameEnd": 67
},
"Args": {
"LeftParenPos": 67,
"RightParenPos": 72,
"Args": [
{
"NumPos": 68,
"NumEnd": 69,
"Literal": "3",
"Base": 10
},
{
"NumPos": 71,
"NumEnd": 72,
"Literal": "6",
"Base": 10
}
]
}
},
"HasFinal": false
},
"StatementEnd": 72,
"SampleRatio": null,
"HasFinal": false
}
},
"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": {
"SelectPos": 81,
"StatementEnd": 112,
"With": null,
"Top": null,
"HasDistinct": false,
"SelectItems": [
{
"Expr": {
"Name": "number",
"QuoteType": 1,
"NamePos": 88,
"NameEnd": 94
},
"Modifiers": [],
"Alias": null
}
],
"From": {
"FromPos": 95,
"Expr": {
"Table": {
"TablePos": 100,
"TableEnd": 112,
"Alias": null,
"Expr": {
"Name": {
"Name": "numbers",
"QuoteType": 1,
"NamePos": 100,
"NameEnd": 107
},
"Args": {
"LeftParenPos": 107,
"RightParenPos": 112,
"Args": [
{
"NumPos": 108,
"NumEnd": 109,
"Literal": "8",
"Base": 10
},
{
"NumPos": 111,
"NumEnd": 112,
"Literal": "9",
"Base": 10
}
]
}
},
"HasFinal": false
},
"StatementEnd": 112,
"SampleRatio": null,
"HasFinal": false
}
},
"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
}
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
[
{
"SelectPos": 0,
"StatementEnd": 14,
"With": null,
"Top": null,
"HasDistinct": false,
"SelectItems": [
{
"Expr": {
"NumPos": 7,
"NumEnd": 8,
"Literal": "1",
"Base": 10
},
"Modifiers": [],
"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": null,
"UnionDistinct": {
"SelectPos": 30,
"StatementEnd": 44,
"With": null,
"Top": null,
"HasDistinct": false,
"SelectItems": [
{
"Expr": {
"NumPos": 37,
"NumEnd": 38,
"Literal": "2",
"Base": 10
},
"Modifiers": [],
"Alias": {
"Name": "v2",
"QuoteType": 1,
"NamePos": 42,
"NameEnd": 44
}
}
],
"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": {
"SelectPos": 60,
"StatementEnd": 74,
"With": null,
"Top": null,
"HasDistinct": false,
"SelectItems": [
{
"Expr": {
"NumPos": 67,
"NumEnd": 68,
"Literal": "3",
"Base": 10
},
"Modifiers": [],
"Alias": {
"Name": "v3",
"QuoteType": 1,
"NamePos": 72,
"NameEnd": 74
}
}
],
"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
},
"Except": null
},
"Except": null
}
]
1 change: 1 addition & 0 deletions parser/testdata/query/select_with_multi_except.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT number FROM numbers(1, 10) EXCEPT SELECT number FROM numbers(3, 6) EXCEPT SELECT number FROM numbers(8, 9)
1 change: 1 addition & 0 deletions parser/testdata/query/select_with_multi_union_distinct.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT 1 AS v1 UNION DISTINCT SELECT 2 AS v2 UNION DISTINCT SELECT 3 AS v3