File tree Expand file tree Collapse file tree 3 files changed +23
-3
lines changed Expand file tree Collapse file tree 3 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -265,7 +265,7 @@ export interface GroupByClause extends BaseNode {
265
265
type : "group_by_clause" ;
266
266
groupByKw : [ Keyword < "GROUP" > , Keyword < "BY" > ] ;
267
267
distinctKw ?: Keyword < "ALL" | "DISTINCT" > ; // PostgreSQL
268
- columns : ListExpr < Expr > | GroupByRollup ;
268
+ columns : ListExpr < Expr | GroupByRollup > ;
269
269
withRollupKw ?: [ Keyword < "WITH" > , Keyword < "ROLLUP" > ] ; // MySQL, MariaDB
270
270
}
271
271
Original file line number Diff line number Diff line change @@ -785,7 +785,7 @@ where_clause
785
785
group_by_clause
786
786
= kws :(GROUP __ BY __ )
787
787
distinctKw :(group_by_distinct __ )?
788
- list :( group_by_rollup / list$expr )
788
+ list :list$grouping_element
789
789
rolKw :(__ WITH __ ROLLUP )? {
790
790
return loc ({
791
791
type: " group_by_clause" ,
@@ -799,8 +799,12 @@ group_by_clause
799
799
group_by_distinct
800
800
= kw :(ALL / DISTINCT ) & postgres { return kw; }
801
801
802
+ grouping_element
803
+ = group_by_rollup
804
+ / expr
805
+
802
806
group_by_rollup
803
- = & bigquery kw :(ROLLUP __ ) cols :paren$list$expr {
807
+ = kw :(ROLLUP __ ) cols :paren$list$expr ( & bigquery / & postgres ) {
804
808
return loc ({
805
809
type: " group_by_rollup" ,
806
810
rollupKw: read (kw),
@@ -4984,6 +4988,7 @@ list$expr = .
4984
4988
list$expr_or_default = .
4985
4989
list$expr_or_explicit_alias = .
4986
4990
list$func_param = .
4991
+ list$grouping_element = .
4987
4992
list$ident = .
4988
4993
list$literal = .
4989
4994
list$named_window = .
Original file line number Diff line number Diff line change @@ -19,6 +19,21 @@ describe("select GROUP BY", () => {
19
19
testClauseWc ( "GROUP BY ROLLUP ( id, name + age )" ) ;
20
20
testClauseWc ( "GROUP BY ROLLUP ( id, (name, age) )" ) ;
21
21
} ) ;
22
+
23
+ dialect ( "postgresql" , ( ) => {
24
+ it ( "supports multiple ROLLUPs in one GROUP BY" , ( ) => {
25
+ testClauseWc ( "GROUP BY ROLLUP(id), ROLLUP(name)" ) ;
26
+ } ) ;
27
+
28
+ it ( "parses multiple ROLLUPs as group_by_rollup nodes" , ( ) => {
29
+ const clause = parseClause ( "GROUP BY ROLLUP(id), ROLLUP(name)" ) ;
30
+ if ( clause . type !== "group_by_clause" ) {
31
+ throw new Error ( "Expected group_by_clause" ) ;
32
+ }
33
+ expect ( clause . columns . items [ 0 ] . type ) . toBe ( "group_by_rollup" ) ;
34
+ expect ( clause . columns . items [ 1 ] . type ) . toBe ( "group_by_rollup" ) ;
35
+ } ) ;
36
+ } ) ;
22
37
} ) ;
23
38
24
39
dialect ( [ "mysql" , "mariadb" ] , ( ) => {
You can’t perform that action at this time.
0 commit comments