Hacker News new | ask | show | jobs
by remram 1408 days ago
Your suggestion is incorrect. CUBE is not part of the expression.
1 comments

Well, I did say I wasn't familiar with it, but it's correct for `coalesce` and I don't think `cube` is different: https://www.postgresql.org/docs/current/cube.html

In the context of `group by` it's treated as grouping sets, but that's not its only use. (Though that does seem to be special cased in terms of parsing, since afaict - I can't find the full query BNF on mobile - `grouping sets` is not optional.)

https://www.postgresql.org/docs/14/sql-select.html

    GROUP BY [ ALL | DISTINCT ] grouping_element [, ...]

    grouping_element can be one of:

        ( )
        expression
        ( expression [, ...] )
        ROLLUP ( { expression | ( expression [, ...] ) } [, ...] )
        CUBE ( { expression | ( expression [, ...] ) } [, ...] )
        GROUPING SETS ( grouping_element [, ...] )
You're right about COALESCE of course.