fix group_by

This commit is contained in:
Christian De la Hoz 2021-08-31 20:30:21 +02:00
parent 4e0cdec7f7
commit 86d51a3d6c
2 changed files with 25 additions and 1 deletions

View File

@ -129,6 +129,24 @@ group by
select name from items group by 1, 2;
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(identifier))
(select_from
(from_item
(from_table
(identifier))))
(select_group_by
(number)
(number))))
================================================================================
group by with parens
================================================================================
select name from items group by (1, 2);
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item

View File

@ -511,7 +511,13 @@ module.exports = grammar({
kw("offset"), $._value_expression,
optional(choice(kw("row"), kw("rows")))
),
select_group_by: $ => seq(kw("group"), kw("by"), commaSep1($._value_expression)),
// TODO(chrde): rollup, cube, grouping sets
select_group_by: $ => prec(1, seq(kw("group"), kw("by"),
choice(
seq("(", commaSep1($._value_expression), ")"),
commaSep1($._value_expression),
),
)),
select_order_by: $ => seq(kw("order"), kw("by"), commaSep1($.order_by_item)),
order_by_item: $ => seq($._value_expression, optional($.order_by_direction)),
order_by_direction: $ => choice(kw("asc"), kw("desc")),