public inbox for [email protected]
help / color / mirror / Atom feedFrom: David G. Johnston <[email protected]>
To: Peter Eisentraut <[email protected]>
Cc: Tom Lane <[email protected]>
Cc: pgsql-hackers <[email protected]>
Cc: David Christensen <[email protected]>
Cc: Jelte Fennema-Nio <[email protected]>
Subject: Re: [PATCH] GROUP BY ALL
Date: Tue, 14 Apr 2026 05:57:27 -0700
Message-ID: <CAKFQuwZ2MoUqWv0oKX4M0d85k92HugdF=1qJzhoC1pO20ywWYA@mail.gmail.com> (raw)
In-Reply-To: <[email protected]>
References: <CAHM0NXjz0kDwtzoe-fnHAqPB1qA8_VJN0XAmCgUZ+iPnvP5LbA@mail.gmail.com>
<CAKFQuwY0vhNG8T+pC3BQJurFi3NN_L1KbEPGagRN3V5nKZcpDQ@mail.gmail.com>
<[email protected]>
<[email protected]>
<CAGECzQSGKWy1tcB8BB=p2suOvW0KLtLR+pm=XTagfp9WSA4HXQ@mail.gmail.com>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
On Tuesday, April 14, 2026, Peter Eisentraut <[email protected]> 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.
view thread (49+ messages)
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected], [email protected]
Subject: Re: [PATCH] GROUP BY ALL
In-Reply-To: <CAKFQuwZ2MoUqWv0oKX4M0d85k92HugdF=1qJzhoC1pO20ywWYA@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox