From 86d51a3d6c4f350d9b9ebfed909897ae4ea56e87 Mon Sep 17 00:00:00 2001 From: Christian De la Hoz Date: Tue, 31 Aug 2021 20:30:21 +0200 Subject: [PATCH] fix group_by --- corpus/select_statement/select.txt | 18 ++++++++++++++++++ grammar.js | 8 +++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/corpus/select_statement/select.txt b/corpus/select_statement/select.txt index 9330089..5edb967 100644 --- a/corpus/select_statement/select.txt +++ b/corpus/select_statement/select.txt @@ -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 diff --git a/grammar.js b/grammar.js index 07cd682..c167078 100644 --- a/grammar.js +++ b/grammar.js @@ -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")),