Skip to content

Commit

Permalink
feat: nested common table expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
dmfay committed Jun 29, 2023
1 parent ddd1763 commit 9d66f30
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 5 deletions.
9 changes: 4 additions & 5 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -598,15 +598,14 @@ module.exports = grammar({
optional(
seq(
optional($.keyword_not),
$.keyword_materialized),
$.keyword_materialized,
),
),
'(',
alias(
choice(
$._select_statement,
$._delete_statement,
$._insert_statement,
$._update_statement,
$._dml_read,
$._dml_write,
),
$.statement,
),
Expand Down
64 changes: 64 additions & 0 deletions test/corpus/cte.txt
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,67 @@ Parenthesized CTE
(relation
(object_reference
(identifier))))))

================================================================================
Nested CTE
================================================================================

WITH top_cte AS (
WITH nested_cte AS (
SELECT 1 as one, 2 as two
)
SELECT one, two
FROM nested_cte
)
SELECT *
FROM top_cte;

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

(program
(statement
(keyword_with)
(cte
(identifier)
(keyword_as)
(statement
(keyword_with)
(cte
(identifier)
(keyword_as)
(statement
(select
(keyword_select)
(select_expression
(term
(literal)
(keyword_as)
(identifier))
(term
(literal)
(keyword_as)
(identifier))))))
(select
(keyword_select)
(select_expression
(term
(field
(identifier)))
(term
(field
(identifier)))))
(from
(keyword_from)
(relation
(object_reference
(identifier))))))
(select
(keyword_select)
(select_expression
(term
(all_fields))))
(from
(keyword_from)
(relation
(object_reference
(identifier))))))

0 comments on commit 9d66f30

Please sign in to comment.