From: Tom Lane <tgl@sss.pgh.pa.us>
To: Vik Fearing <vik@postgresfriends.org>
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: Mon, 21 Jul 2025 18:56:15 -0400
Message-ID: <661034.1753138575@sss.pgh.pa.us> (raw)
In-Reply-To: <6c998e4f-f6f2-43c2-8b67-cfff360ef241@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>
Vik Fearing <vik@postgresfriends.org> writes:
> That is my preferred grammar, thank you. I have not looked at the C
> code by this can be obtained with a syntax transformation. To wit:
> SELECT a, b, c
> FROM tab
> QUALIFY wf() OVER () = ?
> can be rewritten as:
> SELECT a, b, c
> FROM (
> SELECT a, b, c, wf() OVER () = ? AS qc
> FROM tab
> ) AS q
> WHERE qc
That answers another question I was going to raise. Matheus's
opening example was
SELECT depname,
empno,
salary,
RANK() OVER (PARTITION BY depname ORDER BY salary DESC) AS rnk
FROM empsalary
QUALIFY rnk = 1;
which implies that the QUALIFY clause sees the SELECT output columns,
and hence that it can't use any values not emitted by the SELECT list.
Your transformation implies that it sees the same namespace as the
SELECT list, which seems like a much better and less confusing
definition to me.
regards, tom lane
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: tgl@sss.pgh.pa.us, vik@postgresfriends.org, matheusssilv97@gmail.com, peter@eisentraut.org
Subject: Re: Proposal: QUALIFY clause
In-Reply-To: <661034.1753138575@sss.pgh.pa.us>
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> <661034.1753138575@sss.pgh.pa.us>
* 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