Open cploonker opened 4 months ago
Presto has the same issue: https://github.com/prestodb/presto/issues/23151
cc: @martint
Per the SQL specification:
Each
<grouping column reference>
shall unambiguously reference a column of the table resulting from the<from clause>
The way the GROUPING SETS
, ROLLUP
and CUBE
clauses are implemented follow the specification to the letter. Grouping by an expression (in the case of a vanilla GROUP BY
) is an extension to the specification, which predates the implementation of those more advance grouping set qualifiers. We could consider adding the same extensions to those constructs, but there are some non-trivial implications for how grouping()
and other operations such as non-deterministic functions would work, and that would need to be sorted out.
Is a struct field not considered a column?
No, that’s considered a “complex expression” (a field dereference expression)
Got it. Thanks for the explaination. So this is a case of SQL standard coming in the way of ease of use.
@cploonker Is there any workaround for this limitation?
Following query works
However following query fails
Error
Shouldn't both work?