From: Peter Eisentraut Date: Tue, 7 Jul 2026 06:37:15 +0000 (+0200) Subject: Update GROUP BY ALL comments about window functions X-Git-Tag: REL_19_BETA2~43 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7f0998f87b08e325ab65b1355464a1430042b9aa;p=thirdparty%2Fpostgresql.git Update GROUP BY ALL comments about window functions When GROUP BY ALL was added in commit ef38a4d9756, the SQL standard working draft was silent on what to do with window functions. This has now been fixed in the SQL standard working draft. Update the documentation and code comments about that. Also make the documentation more specific that we are only talking about aggregate functions referring to the same query level, which is another thing that has been made more precise in the SQL standard working draft since. The PostgreSQL implementation was already doing the right thing for both aspects, so no functionality changes. Reviewed-by: Tom Lane Discussion: https://www.postgresql.org/message-id/flat/CAHM0NXjz0kDwtzoe-fnHAqPB1qA8_VJN0XAmCgUZ%2BiPnvP5LbA%40mail.gmail.com --- diff --git a/doc/src/sgml/queries.sgml b/doc/src/sgml/queries.sgml index d8d4c3c53ef..b3cfbc93582 100644 --- a/doc/src/sgml/queries.sgml +++ b/doc/src/sgml/queries.sgml @@ -1162,7 +1162,7 @@ SELECT product_id, p.name, (sum(s.units) * p.price) AS sales PostgreSQL also supports the syntax GROUP BY ALL, which is equivalent to explicitly writing all select-list entries that - do not contain either an aggregate function or a window function. + do not contain either an aggregate function referring to the same query level or a window function. This can greatly simplify ad-hoc exploration of data. As an example, these queries are equivalent: diff --git a/doc/src/sgml/ref/select.sgml b/doc/src/sgml/ref/select.sgml index 09b6ce809bb..8d5a751af7e 100644 --- a/doc/src/sgml/ref/select.sgml +++ b/doc/src/sgml/ref/select.sgml @@ -862,7 +862,8 @@ GROUP BY { ALL | [ ALL | DISTINCT ] grouping_elem grouping_elements provided is equivalent to writing GROUP BY with the numbers of all SELECT output columns that do not - contain either an aggregate function or a window function. + contain either an aggregate function referring to the same query level or + a window function. diff --git a/src/backend/parser/parse_clause.c b/src/backend/parser/parse_clause.c index 881fba2e7b5..2f7333e6786 100644 --- a/src/backend/parser/parse_clause.c +++ b/src/backend/parser/parse_clause.c @@ -2817,9 +2817,7 @@ transformGroupClause(ParseState *pstate, List *grouplist, bool groupByAll, /* * Likewise, TLEs containing window functions are not okay to add - * to GROUP BY. At this writing, the SQL standard is silent on - * what to do with them, but by analogy to aggregates we'll just - * skip them. + * to GROUP BY, and the SQL standard directs us to skip them. */ if (pstate->p_hasWindowFuncs && contain_windowfuncs((Node *) tle->expr))