Re: GROUP BY ALL

Поиск
Список
Период
Сортировка
От Isaac Morland
Тема Re: GROUP BY ALL
Дата
Msg-id CAMsGm5f5USbSRugipvbcsQ-bgVicDOgspY97gv8Y1eOWT26rVQ@mail.gmail.com
обсуждение исходный текст
Ответ на Re: GROUP BY ALL  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
On Sun, 18 Dec 2022 at 23:30, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Andrey Borodin <amborodin86@gmail.com> 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.

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Ajin Cherian
Дата:
Сообщение: Re: Support logical replication of DDLs
Следующее
От: Andrew Dunstan
Дата:
Сообщение: meson files copyright