Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

snowflake - support for select stmt in parentheses #4235

Merged
merged 1 commit into from
Sep 15, 2024
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
14 changes: 10 additions & 4 deletions sql/snowflake/SnowflakeParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -4052,15 +4052,15 @@ switch_section

// select
query_statement
: with_expression? select_statement set_operators*
: with_expression? select_statement_in_parentheses set_operators*
;

with_expression
: WITH common_table_expression (COMMA common_table_expression)*
;

common_table_expression
: id_ ('(' columns = column_list ')')? AS '(' select_statement set_operators* ')'
: id_ (LR_BRACKET columns = column_list RR_BRACKET)? AS select_statement_in_parentheses
;

select_statement
Expand All @@ -4069,8 +4069,14 @@ select_statement
;

set_operators
: (UNION ALL? | EXCEPT | MINUS_ | INTERSECT) select_statement //EXCEPT and MINUS have same SQL meaning
| LR_BRACKET select_statement RR_BRACKET
: (UNION ALL? | EXCEPT | MINUS_ | INTERSECT) select_statement_in_parentheses //EXCEPT and MINUS have same SQL meaning
| select_statement_in_parentheses
;

select_statement_in_parentheses
: LR_BRACKET select_statement_in_parentheses RR_BRACKET
| select_statement_in_parentheses set_operators
| select_statement
;

select_optional_clauses
Expand Down
21 changes: 21 additions & 0 deletions sql/snowflake/examples/select.sql
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,24 @@ SELECT EXPR, SCALE, ROUNDING_MODE, SEQUENCE FROM t;

select 'a', 'b',;
with t as (select 'a', 'b',) select * from t;

with a as((
((
select 10 as c
))
union
((
select 11 as d
))
))
, b as (((
((select 2 as e))
)))
select *
from a
union
((select 1 as c));

(((select 10 as c)))
union
((select 11 as d));
Loading