From: Vik Fearing <vik@postgresfriends.org>
To: Nico Williams <nico@cryptonector.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Merlin Moncure <mmoncure@gmail.com>
Cc: Pavel Stehule <pavel.stehule@gmail.com>
Cc: Matheus Alcantara <matheusssilv97@gmail.com>
Cc: Pg Hackers <pgsql-hackers@postgresql.org>
Cc: Peter Eisentraut <peter@eisentraut.org>
Subject: Re: Proposal: QUALIFY clause
Date: Tue, 22 Jul 2025 17:14:33 +0200
Message-ID: <249e3cc4-440e-420d-8307-58b523edc7b0@postgresfriends.org> (raw)
In-Reply-To: <aH+pQ5fvhvl8eLTP@ubby>
References: <CAFY6G8euMWRjTEdRV9M=RL2_EJNDm5UNeHat9U1FGGwzfjGSfw@mail.gmail.com>
<a042f530-90a4-46fc-8595-43053fcfc06e@postgresfriends.org>
<DBI1WKCGAPN4.321XNB6R2YKPT@gmail.com>
<6c998e4f-f6f2-43c2-8b67-cfff360ef241@postgresfriends.org>
<CAFj8pRCNZ8vLca8XK8s-Xha7PDmfw0r_JXnhb8Z87On4O=qctQ@mail.gmail.com>
<CAHyXU0wnmAC2aSJXE8mWarydvQ_gY9OEFrpRNZ9OQ3De3vXZ2A@mail.gmail.com>
<aH8OuSXcoZTL0Vg6@ubby>
<881159.1753161260@sss.pgh.pa.us>
<aH+pQ5fvhvl8eLTP@ubby>
On 22/07/2025 17:07, Nico Williams wrote:
> On Tue, Jul 22, 2025 at 01:14:20AM -0400, Tom Lane wrote:
>> Nico Williams <nico@cryptonector.com> writes:
>>> On Mon, Jul 21, 2025 at 09:43:15PM -0600, Merlin Moncure wrote:
>>>> Hm, HAVING requires to apply 'group by' which windows functions do not
>>>> require (unlike aggregates).
>>> Pavel's point is precisely to allow HAVING w/o a GROUP BY when there are
>>> window functions since window functions are "+/-" ("more or less")
>>> aggregate functions. That makes sense to me.
>> No, it's really quite wrong. Aggregate functions are not equivalent
>> to window functions: if you have both in a query, they execute in
>> separate passes, with the window functions operating on the grouped
>> rows output by the aggregation step (and then filtered by HAVING,
>> if any).
> Pavel doesn't say that window functions are aggregate functions. Pavel
> said they are +/- (more or less, really, just similar to) aggregate
> functions. There is a similarity. But I appreciate the point about
> which passes get which, and that definitely makes the two-HAVING-
> clauses concept much more unwieldy.
Window functions and aggregates have only one thing in common, and that
is that they can both operate on a window frame. Otherwise the
difference is night and day. Especially when you consider nested window
clauses (that postgres does not support yet).
> I agree that its own clause is best; I just greatly dislike QUALIFY.
Sorry.
--
Vik Fearing
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: vik@postgresfriends.org, nico@cryptonector.com, tgl@sss.pgh.pa.us, mmoncure@gmail.com, pavel.stehule@gmail.com, matheusssilv97@gmail.com, peter@eisentraut.org
Subject: Re: Proposal: QUALIFY clause
In-Reply-To: <249e3cc4-440e-420d-8307-58b523edc7b0@postgresfriends.org>
References: <CAFY6G8euMWRjTEdRV9M=RL2_EJNDm5UNeHat9U1FGGwzfjGSfw@mail.gmail.com> <a042f530-90a4-46fc-8595-43053fcfc06e@postgresfriends.org> <DBI1WKCGAPN4.321XNB6R2YKPT@gmail.com> <6c998e4f-f6f2-43c2-8b67-cfff360ef241@postgresfriends.org> <CAFj8pRCNZ8vLca8XK8s-Xha7PDmfw0r_JXnhb8Z87On4O=qctQ@mail.gmail.com> <CAHyXU0wnmAC2aSJXE8mWarydvQ_gY9OEFrpRNZ9OQ3De3vXZ2A@mail.gmail.com> <aH8OuSXcoZTL0Vg6@ubby> <881159.1753161260@sss.pgh.pa.us> <aH+pQ5fvhvl8eLTP@ubby> <249e3cc4-440e-420d-8307-58b523edc7b0@postgresfriends.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox