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

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 →
  1. Add GROUP BY ALL.

  2. Refactor to avoid code duplication in transformPLAssignStmt.

  3. Fix missed copying of groupDistinct in transformPLAssignStmt.