pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Matheus Alcantara <matheusssilv97@gmail.com>
To: Isaac Morland <isaac.morland@gmail.com>
To: 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 11:47:19 -0300
Message-ID: <DBHTCY6HQ1KO.H54EA0FZ4XIN@gmail.com> (raw)
In-Reply-To: <CAMsGm5dAYswFz5RkgEu0ZsGbEJjHaJ3QMOMPYHAGUvY_V69rCg@mail.gmail.com>
References: <CAFY6G8euMWRjTEdRV9M=RL2_EJNDm5UNeHat9U1FGGwzfjGSfw@mail.gmail.com>
	<CA+pG8ePeO1BBdu+fK4ZZiGSAj2PUsy_-ZL2jC61tF8Pym2BC_g@mail.gmail.com>
	<CAMsGm5dAYswFz5RkgEu0ZsGbEJjHaJ3QMOMPYHAGUvY_V69rCg@mail.gmail.com>

On Mon Jul 21, 2025 at 11:29 AM -03, Isaac Morland wrote:
> Is this different from using the window functions in a subquery and then
> applying a WHERE clause on the outer query?
>
> SELECT … FROM (SELECT … [including window functions] FROM …) WHERE [stuff
> that would be in QUALIFY]
>
> I'll be honest, I'm skeptical that we need another keyword that basically
> means “WHERE, but applied at a different point in the query processing”.
> I'm not even convinced that HAVING was a good idea (although obviously I
> would not propose removal).
> 
Thanks for sharing your thoughts!

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.

--
Matheus Alcantara





view thread (41+ messages)  latest in thread

Message-ID: <DBHTCY6HQ1KO.H54EA0FZ4XIN@gmail.com>
Permalink:  ../DBHTCY6HQ1KO.H54EA0FZ4XIN@gmail.com/
Also on:    postgresql.org/message-id/DBHTCY6HQ1KO.H54EA0FZ4XIN@gmail.com

 · 

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: matheusssilv97@gmail.com, isaac.morland@gmail.com, michaeleartz@gmail.com, peter@eisentraut.org
  Subject: Re: Proposal: QUALIFY clause
  In-Reply-To: <DBHTCY6HQ1KO.H54EA0FZ4XIN@gmail.com>
  References: <CAFY6G8euMWRjTEdRV9M=RL2_EJNDm5UNeHat9U1FGGwzfjGSfw@mail.gmail.com> <CA+pG8ePeO1BBdu+fK4ZZiGSAj2PUsy_-ZL2jC61tF8Pym2BC_g@mail.gmail.com> <CAMsGm5dAYswFz5RkgEu0ZsGbEJjHaJ3QMOMPYHAGUvY_V69rCg@mail.gmail.com> <DBHTCY6HQ1KO.H54EA0FZ4XIN@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