Re: [PATCH] GROUP BY ALL
Peter Eisentraut <peter@eisentraut.org>
From: Peter Eisentraut <peter@eisentraut.org>
To: pgsql-hackers <pgsql-hackers@postgresql.org>
Cc: Tom Lane <tgl@sss.pgh.pa.us>,
"David G. Johnston" <david.g.johnston@gmail.com>,
David Christensen <david@pgguru.net>, Jelte Fennema-Nio <postgres@jeltef.nl>
Date: 2026-06-30T13:15:19Z
Lists: pgsql-hackers
Attachments
- 0001-Update-GROUP-BY-ALL-comments-about-window-functions.patch (text/plain) patch 0001
- gru058-GROUP BY ALL vs. subqueries (#74, P02-DEU-130).pdf (application/pdf)
- bma019-GROUP BY ALL and window functions.pdf (application/pdf)
On 14.04.26 13:21, Peter Eisentraut wrote: > The handling of window functions by GROUP BY ALL is a semi-open-item. > > The code in transformGroupClause() currently says: > > /* > * 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. > */ > if (pstate->p_hasWindowFuncs && > contain_windowfuncs((Node *) tle->expr)) > continue; > > The wording of the SQL standard currently does not address that at all > (but we could fix it), which would mean that a window function ends up > in the GROUP BY ALL expansion by default. > > Personally, I don't understand what the meaning of this should be. > Aggregates relate to grouping, but window functions are a different > processing phase, so that do they have to do with grouping? At the most recent SQL standard meeting, I had this issue addressed, and the handling of window functions in GROUP BY ALL is now specified to work like PostgreSQL already works. I propose the attached patch that updates the code comment about that, and also makes the documentation more specific that we are only talking about aggregate functions and window functions referring to the same query level, which is another thing the original specification was silent about but which has since been fixed. The two SQL change proposal papers are attached for reference.
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Add GROUP BY ALL.
- ef38a4d9756d 19 (unreleased) landed
-
Refactor to avoid code duplication in transformPLAssignStmt.
- b0fb2c6aa5a4 19 (unreleased) landed
-
Fix missed copying of groupDistinct in transformPLAssignStmt.
- b7f6798c056a 16.11 landed
- 9ca79896aba3 15.15 landed
- 78a284b0b8d4 18.1 landed
- 7504d2be9eb4 19 (unreleased) landed
- 3fc9aa5b0233 17.7 landed
- 0be39b4b1a01 14.20 landed