From: Matheus Alcantara <matheusssilv97@gmail.com>
To: Marcos Pegoraro <marcos@f10.com.br>
Cc: Vik Fearing <vik@postgresfriends.org>
Cc: Pg Hackers <pgsql-hackers@postgresql.org>
Cc: Peter Eisentraut <peter@eisentraut.org>
Subject: Re: Proposal: QUALIFY clause
Date: Tue, 22 Jul 2025 15:54:19 -0300
Message-ID: <DBIT8MD9O3W8.2ZPWNBOAZ5IBE@gmail.com> (raw)
In-Reply-To: <CAB-JLwboVrNVRPD4CC1bJhgJQB50wcUn-NWkfgEpfXsmby1spg@mail.gmail.com>
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>
<DBIKCA3XAHPS.QIAI5362CP5M@gmail.com>
<CAB-JLwboVrNVRPD4CC1bJhgJQB50wcUn-NWkfgEpfXsmby1spg@mail.gmail.com>
On Tue Jul 22, 2025 at 3:11 PM -03, Marcos Pegoraro wrote:
> Em ter., 22 de jul. de 2025 às 08:56, Matheus Alcantara <
> matheusssilv97@gmail.com> escreveu:
>
>> The current patch supports the following syntaxes:
>> SELECT a, b, c
>> wf() OVER () as d
>> FROM tab
>> QUALIFY d = 1
>> When using the "QUALIFY d = 1" form, I currently rewrite the expression
>> as "wf() OVER () = 1" by searching the targetlist for the matching
>> alias, replacing the Var with the corresponding WindowFunc.
>>
>
> Not related to $subject but that way you did,
> that replacement alias for wf expression, is cool.
> With that would it be possible to have where replacements too ? Maybe.
>
> select a+b as ab from t where ab = 5
>
Do you mean instead of reference the "ab" using a Var it replaces with a
OpExpr of "a+b"? I think that it would be possible, but the current
implementation is not fully correct, it only works for OpExpr's. Using
AND/OR operators does not work and I think that to make it fully correct
is more complex, so I think that rewriting the query to use a subquery
as Vik suggested on [1] fixes this issue and also makes it easier to
understand.
(this happens on transformQualifyClause() if you want to take a look)
[1] https://www.postgresql.org/message-id/6c998e4f-f6f2-43c2-8b67-cfff360ef241%40postgresfriends.org
--
Matheus Alcantara
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: matheusssilv97@gmail.com, marcos@f10.com.br, vik@postgresfriends.org, peter@eisentraut.org
Subject: Re: Proposal: QUALIFY clause
In-Reply-To: <DBIT8MD9O3W8.2ZPWNBOAZ5IBE@gmail.com>
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> <DBIKCA3XAHPS.QIAI5362CP5M@gmail.com> <CAB-JLwboVrNVRPD4CC1bJhgJQB50wcUn-NWkfgEpfXsmby1spg@mail.gmail.com> <DBIT8MD9O3W8.2ZPWNBOAZ5IBE@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 DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox