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 1udx6E-002ozZ-B5 for pgsql-hackers@arkaria.postgresql.org; Mon, 21 Jul 2025 20:27:03 +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 1udx6D-002p8V-6B for pgsql-hackers@arkaria.postgresql.org; Mon, 21 Jul 2025 20:27:01 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1udx6C-002p8M-Sg for pgsql-hackers@lists.postgresql.org; Mon, 21 Jul 2025 20:27:01 +0000 Received: from relay9-d.mail.gandi.net ([2001:4b98:dc4:8::229]) by makus.postgresql.org with smtp (Exim 4.96) (envelope-from ) id 1udx69-00057F-2c for pgsql-hackers@postgresql.org; Mon, 21 Jul 2025 20:26:59 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id D3CB2443FF; Mon, 21 Jul 2025 20:26:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=postgresfriends.org; s=gm1; t=1753129613; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nC8zS3+r3j64gOvWSsKmR38JI/2x3/XSTUKZS41tX2k=; b=KNVmSoXXlEu3OGFaxwjpArtmtH6LIGkPgQqcJwPYSdxHvvKiPN83SM4PalU7JLNty4JeIH KAM0xGN99Taq2He7N0U78yPH8GRZIZETFgDriRtuy3x3bw1qlZNxjoZBlnf0o4Z80FnhTj oKozK4MGcogGFHVbpG95qqSav0Ybz+riylombdGojqtxlRGoBVVGCao02AX7yAxcv+r2I+ DTB3VWoaWNMlQ6vK+Jqpzo1eiNqIbGRjygmUNFrqBMz51Qdq0ZEbLfkZZfmu4hUpxnyVGW YcFjmocGJs62fWxVOEEJbAkdc91Ob2JdwMQRCl2HkTezxr+Dy/AdOHOgM0QJcg== Message-ID: <0b190baa-460d-48a8-9f7f-ca8c8cfe13bd@postgresfriends.org> Date: Mon, 21 Jul 2025 22:26:51 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Proposal: QUALIFY clause To: Tom Lane , Matheus Alcantara Cc: Isaac Morland , Mike Artz , Pg Hackers , Peter Eisentraut References: <463108.1753119052@sss.pgh.pa.us> Content-Language: en-US From: Vik Fearing In-Reply-To: <463108.1753119052@sss.pgh.pa.us> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdejfedtfecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhepkfffgggfuffvvehfhfgjtgfgsehtkeertddtvdejnecuhfhrohhmpeggihhkucfhvggrrhhinhhguceovhhikhesphhoshhtghhrvghsfhhrihgvnhgushdrohhrgheqnecuggftrfgrthhtvghrnhepuddtveefleegvddutdejhffhleehhfevheeilefhgeettdeuhfdtffegvdfgteffnecukfhppedvrgdtvdemkeegvdekmeduudgvtdemvdejtddumegrgegvudemgedvfhegmegrlegrkeemkegvieeknecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepvdgrtddvmeekgedvkeemudduvgdtmedvjedtudemrgegvgdumeegvdhfgeemrgelrgekmeekvgeikedphhgvlhhopeglkffrggeimedvrgdtvdemkeegvdekmeduudgvtdemvdejtddumegrgegvudemgedvfhegmegrlegrkeemkegvieekngdpmhgrihhlfhhrohhmpehvihhksehpohhsthhgrhgvshhfrhhivghnughsrdhorhhgpdhnsggprhgtphhtthhopeeipdhrtghpthhtohepthhglhesshhsshdrphhghhdrphgrrdhushdprhgtphhtthhopehmrghthhgvuhhsshhsihhlvheljeesghhmrghilhdrtghomhdprhgtphhtthhopehishgrr ggtrdhmohhrlhgrnhgusehgmhgrihhlrdgtohhmpdhrtghpthhtohepmhhitghhrggvlhgvrghrthiisehgmhgrihhlrdgtohhmpdhrtghpthhtohepphhgshhqlhdqhhgrtghkvghrshesphhoshhtghhrvghsqhhlrdhorhhgpdhrtghpthhtohepphgvthgvrhesvghishgvnhhtrhgruhhtrdhorhhg X-GND-Sasl: vik@postgresfriends.org List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 21/07/2025 19:30, Tom Lane wrote: > "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". 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