Re: proposal - GROUPING SETS

From: "Greg Stark" <stark(at)enterprisedb(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>, "PostgreSQL-development Hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal - GROUPING SETS
Date: 2008-09-16 14:43:52
Message-ID: 4136ffa0809160743l5880340bx65096606a89ee34b@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Sep 16, 2008 at 3:02 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2008-09-16 14:47:07 Re: Autovacuum and Autoanalyze
Previous Message Simon Riggs 2008-09-16 14:40:09 Re: Subtransaction commits and Hot Standby