Skip to content

Commit

Permalink
feat: add cross join unnest with ordinality
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias-Q committed Nov 15, 2024
1 parent f833028 commit b92c3e9
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 @@ -294,6 +294,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 @@ -3114,10 +3115,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 @@ -267,6 +267,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 b92c3e9

Please sign in to comment.