Re: proposal - GROUPING SETS - Mailing list pgsql-hackers

From Greg Stark
Subject Re: proposal - GROUPING SETS
Date
Msg-id 4136ffa0809160743l5880340bx65096606a89ee34b@mail.gmail.com
Whole thread Raw
In response to Re: proposal - GROUPING SETS  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: proposal - GROUPING SETS  ("Pavel Stehule" <pavel.stehule@gmail.com>)
List pgsql-hackers
On Tue, Sep 16, 2008 at 3:02 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> "Pavel Stehule" <pavel.stehule@gmail.com> writes:
>> select a, b from t group by grouping sets(a, b);
>
>> is same as:
>
>> select a, NULL from t group by a
>> union all
>> select NULL, b from t group by b;
>
> Really?  That seems utterly bizarre, not to say pointless.
> You sure you read the spec correctly?

I think that's basically right but IIRC you need another set of
parentheses so it's GROUPING SETS ((a),(b))

Basically grouping sets are a generalized form of rollup and cube. If
you did GROUPING SETS ((a),(a,b),(a,b,c)) you would get the same as
ROLLUP. And if you listed every possible subset of the grouping
columns it would be the equivalent of CUBE. But it lets you specify an
arbitrary subset of the combinations that CUBE would return.

-- 
greg


pgsql-hackers by date:

Previous
From: Simon Riggs
Date:
Subject: Re: Subtransaction commits and Hot Standby
Next
From: Tom Lane
Date:
Subject: Re: Autovacuum and Autoanalyze