pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Vik Fearing <vik@postgresfriends.org>
To: Tom Lane <tgl@sss.pgh.pa.us>
To: Matheus Alcantara <matheusssilv97@gmail.com>
Cc: Isaac Morland <isaac.morland@gmail.com>
Cc: Mike Artz <michaeleartz@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 22:26:51 +0200
Message-ID: <0b190baa-460d-48a8-9f7f-ca8c8cfe13bd@postgresfriends.org> (raw)
In-Reply-To: <463108.1753119052@sss.pgh.pa.us>
References: <CAFY6G8euMWRjTEdRV9M=RL2_EJNDm5UNeHat9U1FGGwzfjGSfw@mail.gmail.com>
	<CA+pG8ePeO1BBdu+fK4ZZiGSAj2PUsy_-ZL2jC61tF8Pym2BC_g@mail.gmail.com>
	<CAMsGm5dAYswFz5RkgEu0ZsGbEJjHaJ3QMOMPYHAGUvY_V69rCg@mail.gmail.com>
	<DBHTCY6HQ1KO.H54EA0FZ4XIN@gmail.com>
	<463108.1753119052@sss.pgh.pa.us>


On 21/07/2025 19:30, Tom Lane wrote:
> "Matheus Alcantara" <matheusssilv97@gmail.com> writes:
>> You're right — semantically, using QUALIFY is equivalent to wrapping the
>> query in a subquery and applying a WHERE clause to the result. The main
>> motivation here is to provide a more ergonomic and readable syntax.
>> While I understand the hesitation around introducing another keyword
>> that effectively acts like WHERE at a different stage, I believe QUALIFY
>> improves clarity in many use cases, by avoiding the boilerplate and
>> visual noise of nested subqueries making it easier to write and reason
>> about.
> There are concrete reasons not to do this until/unless it becomes
> standardized:
>
> * If the syntax is like WHERE, there will be no way to do it without
> making QUALIFY a fully-reserved word.  That will inevitably break
> more than zero applications.  It's a lot easier to justify that
> sort of breakage if we can say "QUALIFY is reserved according to
> SQL:20xx, so don't blame us".


Yes, it will need to be reserved.


> * I'm not exactly convinced that the committee would standardize
> it just like this.  For one thing, QUALIFY is not even the right
> part of speech: it's a verb, and thus more fit to be a primary
> statement keyword.  What you need here is an adverb (I think ...
> been a long time since high school English, but my dictionary
> says WHERE is an adverb).  Maybe they'd be persuaded to do what
> the existing implementations did, but I wouldn't be at all surprised
> if they choose a different keyword.


I am pretty sure that the keyword will be QUALIFY. There are just too 
many existing implementations for the standard to go against them all.  
(Also, another rdbms just implemented it that way in their upcoming 
product.)


I agree that we should hold back until the standard accepts it, but 
having a working patch ready to go seems like a good idea.

-- 

Vik Fearing






view thread (41+ messages)  latest in thread

Message-ID: <0b190baa-460d-48a8-9f7f-ca8c8cfe13bd@postgresfriends.org>
Permalink:  ../0b190baa-460d-48a8-9f7f-ca8c8cfe13bd@postgresfriends.org/
Also on:    postgresql.org/message-id/0b190baa-460d-48a8-9f7f-ca8c8cfe13bd@postgresfriends.org

 · 

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 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, tgl@sss.pgh.pa.us, matheusssilv97@gmail.com, isaac.morland@gmail.com, michaeleartz@gmail.com, peter@eisentraut.org
  Subject: Re: Proposal: QUALIFY clause
  In-Reply-To: <0b190baa-460d-48a8-9f7f-ca8c8cfe13bd@postgresfriends.org>
  References: <CAFY6G8euMWRjTEdRV9M=RL2_EJNDm5UNeHat9U1FGGwzfjGSfw@mail.gmail.com> <CA+pG8ePeO1BBdu+fK4ZZiGSAj2PUsy_-ZL2jC61tF8Pym2BC_g@mail.gmail.com> <CAMsGm5dAYswFz5RkgEu0ZsGbEJjHaJ3QMOMPYHAGUvY_V69rCg@mail.gmail.com> <DBHTCY6HQ1KO.H54EA0FZ4XIN@gmail.com> <463108.1753119052@sss.pgh.pa.us> <0b190baa-460d-48a8-9f7f-ca8c8cfe13bd@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