Skip to content

Commit

Permalink
Merge pull request #288 from matthias-Q/cross_join_unnest
Browse files Browse the repository at this point in the history
feat: add `cross join unnest with ordinality`
  • Loading branch information
matthias-Q authored Nov 19, 2024
2 parents 40d1503 + b92c3e9 commit d8180fe
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 4 deletions.
24 changes: 20 additions & 4 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ module.exports = grammar({
keyword_out: _ => make_keyword("out"),
keyword_inout: _ => make_keyword("inout"),
keyword_variadic: _ => make_keyword("variadic"),
keyword_ordinality: _ => make_keyword("ordinality"),

keyword_session: _ => make_keyword("session"),
keyword_isolation: _ => make_keyword("isolation"),
Expand Down Expand Up @@ -3166,10 +3167,25 @@ module.exports = grammar({
)
),

cross_join: $ => seq(
$.keyword_cross,
$.keyword_join,
$.relation,
cross_join: $ => prec.right(
seq(
$.keyword_cross,
$.keyword_join,
$.relation,
optional(
seq(
$.keyword_with,
$.keyword_ordinality,
optional(
seq(
$.keyword_as,
field("alias", $.identifier),
paren_list($.identifier),
)
)
)
)
)
),

lateral_join: $ => seq(
Expand Down
1 change: 1 addition & 0 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@
(keyword_out)
(keyword_inout)
(keyword_variadic)
(keyword_ordinality)
(keyword_session)
(keyword_isolation)
(keyword_level)
Expand Down
66 changes: 66 additions & 0 deletions test/corpus/select.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2970,3 +2970,69 @@ FROM (
(object_reference
(identifier))))))
(identifier)))))

================================================================================
SELECT FROM UNNESTED ARRAY WITH ORDINALITY
================================================================================

SELECT numbers, n, a
FROM (
VALUES
(ARRAY[2, 5]),
(ARRAY[7, 8, 9])
) AS x (numbers)
CROSS JOIN UNNEST(numbers) WITH ORDINALITY AS t (n, a);

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

(program
(statement
(select
(keyword_select)
(select_expression
(term
(field
(identifier)))
(term
(field
(identifier)))
(term
(field
(identifier)))))
(from
(keyword_from)
(relation
(values
(keyword_values)
(list
(array
(keyword_array)
(literal)
(literal)))
(list
(array
(keyword_array)
(literal)
(literal)
(literal))))
(keyword_as)
(identifier)
(list
(column
(identifier))))
(cross_join
(keyword_cross)
(keyword_join)
(relation
(invocation
(object_reference
(identifier))
(term
(field
(identifier)))))
(keyword_with)
(keyword_ordinality)
(keyword_as)
(identifier)
(identifier)
(identifier)))))

0 comments on commit d8180fe

Please sign in to comment.