]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Update GROUP BY ALL comments about window functions
authorPeter Eisentraut <peter@eisentraut.org>
Tue, 7 Jul 2026 06:37:15 +0000 (08:37 +0200)
committerPeter Eisentraut <peter@eisentraut.org>
Tue, 7 Jul 2026 06:46:41 +0000 (08:46 +0200)
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 <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/CAHM0NXjz0kDwtzoe-fnHAqPB1qA8_VJN0XAmCgUZ%2BiPnvP5LbA%40mail.gmail.com

doc/src/sgml/queries.sgml
doc/src/sgml/ref/select.sgml
src/backend/parser/parse_clause.c

index d8d4c3c53ef21d3e1153a805dc216db6fc0ba38a..b3cfbc93582b702718eaa5b5636f3f516cf2bcce 100644 (file)
@@ -1162,7 +1162,7 @@ SELECT product_id, p.name, (sum(s.units) * p.price) AS sales
    <para>
     PostgreSQL also supports the syntax <literal>GROUP BY ALL</literal>,
     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:
 <screen>
index 09b6ce809bb16ae30ed359dbc91b5ae9ca38eea5..8d5a751af7e9f3a03affe372d33fe9fa3aea988d 100644 (file)
@@ -862,7 +862,8 @@ GROUP BY { ALL | [ ALL | DISTINCT ] <replaceable class="parameter">grouping_elem
     <replaceable class="parameter">grouping_elements</replaceable>
     provided is equivalent to writing <literal>GROUP BY</literal> with the
     numbers of all <command>SELECT</command> 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.
    </para>
 
    <para>
index 881fba2e7b5bcb4b57bd61050b8bc2682c67f038..2f7333e6786ad29df15a454e360d7aa0ea17e3e8 100644 (file)
@@ -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))