Skip to content

Commit

Permalink
Merge pull request #180 from matthias-Q/subquery_unions
Browse files Browse the repository at this point in the history
fix: subquery unions & invalid tests
  • Loading branch information
matthias-Q committed Jul 13, 2023
2 parents 00ae620 + 0f02bbd commit e40d0c1
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 19 deletions.
6 changes: 1 addition & 5 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2372,11 +2372,7 @@ module.exports = grammar({
),

subquery: $ => wrapped_in_parenthesis(
seq(
$.select,
optional($.from),
optional(";"),
),
$._dml_read
),

list: $ => paren_list($._expression),
Expand Down
6 changes: 3 additions & 3 deletions test/corpus/functions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ SELECT *
FROM foo
WHERE id IN (
SELECT 1
FROM bar;
FROM bar
)

--------------------------------------------------------------------------------
Expand Down Expand Up @@ -397,11 +397,11 @@ WHERE (
NOT EXISTS (
SELECT 1
FROM bar
WHERE 0;
WHERE 0
) OR EXISTS (
SELECT 1
FROM baz
WHERE 1;
WHERE 1
)
)

Expand Down
74 changes: 63 additions & 11 deletions test/corpus/select.txt
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,8 @@ WHERE id NOT IN(1,2);
left: (field
name: (identifier))
operator: (not_in
(keyword_not)
(keyword_in))
(keyword_not)
(keyword_in))
right: (list
(literal)
(literal)))))))
Expand Down Expand Up @@ -452,16 +452,16 @@ WHERE id NOT IN(1,2) AND id NOT IN (SELECT id FROM other_table);
(keyword_in))
right: (subquery
(select
(keyword_select)
(select_expression
(term
value: (field
name: (identifier)))))
(keyword_select)
(select_expression
(term
value: (field
name: (identifier)))))
(from
(keyword_from)
(relation
(object_reference
name: (identifier)))))))))))
(keyword_from)
(relation
(object_reference
name: (identifier)))))))))))

================================================================================
Simple select with IF
Expand Down Expand Up @@ -2897,3 +2897,55 @@ FROM tab
(relation
(object_reference
(identifier))))))

================================================================================
SELECT FROM SUBQUERY WITH UNION
================================================================================

SELECT
a1.*
FROM (
SELECT * FROM tb01
UNION ALL
SELECT * FROM tb01
) a1;

--------------------------------------------------------------------------------

(program
(statement
(select
(keyword_select)
(select_expression
(term
(all_fields
(object_reference
(identifier))))))
(from
(keyword_from)
(relation
(subquery
(set_operation
(select
(keyword_select)
(select_expression
(term
(all_fields))))
(from
(keyword_from)
(relation
(object_reference
(identifier))))
(keyword_union)
(keyword_all)
(select
(keyword_select)
(select_expression
(term
(all_fields))))
(from
(keyword_from)
(relation
(object_reference
(identifier))))))
(identifier)))))

0 comments on commit e40d0c1

Please sign in to comment.