pgsql: Add GROUP BY ALL.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Add GROUP BY ALL.
Date: 2025-09-29 20:55:22
Message-ID: E1v3Ku2-000gC2-18@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Add GROUP BY ALL.

GROUP BY ALL is a form of GROUP BY that adds any TargetExpr that does
not contain an aggregate or window function into the groupClause of
the query, making it exactly equivalent to specifying those same
expressions in an explicit GROUP BY list.

This feature is useful for certain kinds of data exploration. It's
already present in some other DBMSes, and the SQL committee recently
accepted it into the standard, so we can be reasonably confident in
the syntax being stable. We do have to invent part of the semantics,
as the standard doesn't allow for expressions in GROUP BY, so they
haven't specified what to do with window functions. We assume that
those should be treated like aggregates, i.e., left out of the
constructed GROUP BY list.

In passing, wordsmith some existing documentation about GROUP BY,
and update some neglected synopsis entries in select_into.sgml.

Author: David Christensen <david(at)pgguru(dot)net>
Reviewed-by: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Discussion: https://postgr.es/m/CAHM0NXjz0kDwtzoe-fnHAqPB1qA8_VJN0XAmCgUZ+iPnvP5LbA@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/ef38a4d9756db9ae1d20f40aa39f3cf76059b81a

Modified Files
--------------
doc/src/sgml/queries.sgml | 30 +++++++-
doc/src/sgml/ref/select.sgml | 22 ++++--
doc/src/sgml/ref/select_into.sgml | 6 +-
src/backend/parser/analyze.c | 2 +
src/backend/parser/gram.y | 14 ++++
src/backend/parser/parse_clause.c | 65 +++++++++++++++-
src/backend/utils/adt/ruleutils.c | 4 +-
src/include/catalog/catversion.h | 2 +-
src/include/nodes/parsenodes.h | 4 +-
src/include/parser/parse_clause.h | 1 +
src/test/regress/expected/aggregates.out | 123 +++++++++++++++++++++++++++++++
src/test/regress/sql/aggregates.sql | 54 ++++++++++++++
12 files changed, 312 insertions(+), 15 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Michael Paquier 2025-09-30 00:03:08 pgsql: injection_points: Add proper locking when reporting fixed-variab
Previous Message David Rowley 2025-09-29 19:38:22 pgsql: Remove unused parameter from find_window_run_conditions()