From: | Nico Williams <nico(at)cryptonector(dot)com> |
---|---|
To: | Merlin Moncure <mmoncure(at)gmail(dot)com> |
Cc: | Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Vik Fearing <vik(at)postgresfriends(dot)org>, Matheus Alcantara <matheusssilv97(at)gmail(dot)com>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>, Peter Eisentraut <peter(at)eisentraut(dot)org> |
Subject: | Re: Proposal: QUALIFY clause |
Date: | 2025-07-22 15:04:01 |
Message-ID: | aH+oYUO0NrAvTd9P@ubby |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Mon, Jul 21, 2025 at 11:02:36PM -0600, Merlin Moncure wrote:
> On Mon, Jul 21, 2025 at 10:08 PM Nico Williams <nico(at)cryptonector(dot)com>
> wrote:
> > I would have a HAVING clause that comes _before_ GROUP BY apply to
> > window functions and a second one that comes _after_ GROUP BY apply to
> > the grouping.
>
> I don't know...consider:
> #1 SELECT lag(1) OVER(), max(v) FROM (SELECT 1 AS v) q HAVING true ;
> ...
> #2 SELECT lag(1) OVER(), max(v) FROM (SELECT 1 AS v) q HAVING true HAVING
> lag(1) OVER() IS NULL;
>
> What does the HAVING clause apply to in #1? I think you might be in
> trouble with the standard here. 2nd clause doesn't feel right in #2. The
> basic problem is that HAVING does more than just 'syntax sugar subquery /
> WHERE' and it just can't be hijacked to do something else IMO.
#2 would be a syntax error because the second HAVING did not come after
a GROUP BY. #1 would not be a syntax error only because of the use of
window functions before the HAVING.
> Syntax simplifying
> SELECT * FROM (<window function query>) WHERE col = x
Yes. I'd rather that than QUALIFY. QUALIFY only makes sense because so
many other RDBMSes have it and it's likely to get standardized.
Nico
--
From | Date | Subject | |
---|---|---|---|
Next Message | Nico Williams | 2025-07-22 15:07:47 | Re: Proposal: QUALIFY clause |
Previous Message | Andres Freund | 2025-07-22 14:57:06 | Custom pgstat support performance regression for simple queries |