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 1ue5Kj-004pP0-Pa for pgsql-hackers@arkaria.postgresql.org; Tue, 22 Jul 2025 05:14:34 +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 1ue5Ki-0052iO-Op for pgsql-hackers@arkaria.postgresql.org; Tue, 22 Jul 2025 05:14:33 +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 1ue5Ki-0052iF-FS for pgsql-hackers@lists.postgresql.org; Tue, 22 Jul 2025 05:14:32 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1ue5Kg-000921-3D for pgsql-hackers@postgresql.org; Tue, 22 Jul 2025 05:14:31 +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 56M5EKY3881160; Tue, 22 Jul 2025 01:14:20 -0400 From: Tom Lane To: Nico Williams cc: Merlin Moncure , Pavel Stehule , Vik Fearing , Matheus Alcantara , Pg Hackers , Peter Eisentraut Subject: Re: Proposal: QUALIFY clause In-reply-to: References: <6c998e4f-f6f2-43c2-8b67-cfff360ef241@postgresfriends.org> Comments: In-reply-to Nico Williams message dated "Mon, 21 Jul 2025 23:08:25 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <881158.1753161260.1@sss.pgh.pa.us> Date: Tue, 22 Jul 2025 01:14:20 -0400 Message-ID: <881159.1753161260@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Nico Williams writes: > On Mon, Jul 21, 2025 at 09:43:15PM -0600, Merlin Moncure wrote: >> Hm, HAVING requires to apply 'group by' which windows functions do not >> require (unlike aggregates). > Pavel's point is precisely to allow HAVING w/o a GROUP BY when there are > window functions since window functions are "+/-" ("more or less") > aggregate functions. That makes sense to me. No, it's really quite wrong. Aggregate functions are not equivalent to window functions: if you have both in a query, they execute in separate passes, with the window functions operating on the grouped rows output by the aggregation step (and then filtered by HAVING, if any). If we're going to support this, it does need to be its own clause. regards, tom lane