Re: [PATCH] GROUP BY ALL
David G. Johnston <david.g.johnston@gmail.com>
From: "David G. Johnston" <david.g.johnston@gmail.com>
To: Peter Eisentraut <peter@eisentraut.org>
Cc: Tom Lane <tgl@sss.pgh.pa.us>,
pgsql-hackers <pgsql-hackers@postgresql.org>, David Christensen <david@pgguru.net>, Jelte Fennema-Nio <postgres@jeltef.nl>
Date: 2026-04-14T12:57:27Z
Lists: pgsql-hackers
On Tuesday, April 14, 2026, Peter Eisentraut <peter@eisentraut.org> wrote:
>
>
> I don't see any mention of using GROUP BY with window functions in our
> relevant documentation, for example
>
> https://www.postgresql.org/docs/devel/sql-expressions.html#
> SYNTAX-WINDOW-FUNCTIONS
> https://www.postgresql.org/docs/devel/functions-window.html
The select reference page covers this. But the window clause could get
better treatment, it’s buried in step 5.
https://www.postgresql.org/docs/current/sql-select.html
> Commit ef38a4d9756 added a regression test
>
> EXPLAIN (COSTS OFF) SELECT a, COUNT(a) OVER (PARTITION BY a) FROM t1 GROUP
> BY ALL;
>
> but the test table contains no data, so I don't know if this kind of query
> produces interesting information.
>
Each non-null value of “a” would have an output of 1, while a null valued
“a” would have an output of 0. “A” is grouped since all expressions
involving “a” are non-aggregated. The equivalent rewrite is:
Select a, count(a_expr) over … from ( — step 5
select a, a as a_expr from tbl group by all. — step 4
);
For purposes of group by all one would erase/ignore the actual window
wrapper while leaving the expressions it operates over in place. This
extends from “window expressions are processed after group by/having”
documented in SELECT. IOW, group by all resolves during processing step 4
with intermediate results for the expressions within the window functions,
then step 5 removes the intermediate expressions that don’t appear in the
final output while adding in the results of processing the window functions.
David J.
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