public inbox for [email protected]
help / color / mirror / Atom feedFrom: Isaac Morland <[email protected]>
To: Tom Lane <[email protected]>
Cc: Andrey Borodin <[email protected]>
Cc: pgsql-hackers <[email protected]>
Subject: Re: GROUP BY ALL
Date: Mon, 19 Dec 2022 08:44:39 -0500
Message-ID: <CAMsGm5f5USbSRugipvbcsQ-bgVicDOgspY97gv8Y1eOWT26rVQ@mail.gmail.com> (raw)
In-Reply-To: <[email protected]>
References: <CAAhFRxjyTO5BHn9y1oOSEp0TtpTDTTTb7HJBNhTG+i3-hXC0XQ@mail.gmail.com>
<[email protected]>
On Sun, 18 Dec 2022 at 23:30, Tom Lane <[email protected]> wrote:
> Andrey Borodin <[email protected]> writes:
> > I saw a thread in a social network[0] about GROUP BY ALL. The idea seems
> useful.
>
> Isn't that just a nonstandard spelling of SELECT DISTINCT?
>
In a pure relational system, yes; but since Postgres allows duplicate rows,
both in actual table data and in intermediate and final result sets, no.
Although I'm pretty sure no aggregates other than count() are useful - any
other aggregate would always just combine count() copies of the duplicated
value in some way.
What would happen if there are aggregate functions in the tlist?
> I'm not especially on board with "ALL" meaning "ALL (oh, but not
> aggregates)".
>
The requested behaviour can be accomplished by an invocation something like:
select (t).*, count(*) from (select (…field1, field2, …) as t from
…tables…) s group by t;
So we collect all the required fields as a tuple, group by the tuple, and
then unpack it into separate columns in the outer query.
view thread (42+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected]
Subject: Re: GROUP BY ALL
In-Reply-To: <CAMsGm5f5USbSRugipvbcsQ-bgVicDOgspY97gv8Y1eOWT26rVQ@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox