Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uduLs-002Jdt-RA for pgsql-hackers@arkaria.postgresql.org; Mon, 21 Jul 2025 17:31:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uduLr-0021lw-Io for pgsql-hackers@arkaria.postgresql.org; Mon, 21 Jul 2025 17:30:59 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uduLr-0021ln-9Y for pgsql-hackers@lists.postgresql.org; Mon, 21 Jul 2025 17:30:59 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uduLo-0004lV-0C for pgsql-hackers@postgresql.org; Mon, 21 Jul 2025 17:30:59 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 56LHUq9a463109; Mon, 21 Jul 2025 13:30:52 -0400 From: Tom Lane To: "Matheus Alcantara" cc: "Isaac Morland" , "Mike Artz" , "Pg Hackers" , "Peter Eisentraut" Subject: Re: Proposal: QUALIFY clause In-reply-to: References: Comments: In-reply-to "Matheus Alcantara" message dated "Mon, 21 Jul 2025 11:47:19 -0300" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <463107.1753119052.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Mon, 21 Jul 2025 13:30:52 -0400 Message-ID: <463108.1753119052@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "Matheus Alcantara" 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". * 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. regards, tom lane