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 1ueEhV-006jUn-7w for pgsql-hackers@arkaria.postgresql.org; Tue, 22 Jul 2025 15:14:41 +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 1ueEhU-009ClN-C6 for pgsql-hackers@arkaria.postgresql.org; Tue, 22 Jul 2025 15:14:40 +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 1ueEhT-009Ck1-OG for pgsql-hackers@lists.postgresql.org; Tue, 22 Jul 2025 15:14:40 +0000 Received: from relay1-d.mail.gandi.net ([217.70.183.193]) by makus.postgresql.org with smtp (Exim 4.96) (envelope-from ) id 1ueEhS-000DvH-0b for pgsql-hackers@postgresql.org; Tue, 22 Jul 2025 15:14:39 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id E84F043A26; Tue, 22 Jul 2025 15:14:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=postgresfriends.org; s=gm1; t=1753197275; 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=/RngjgZNuWemteL6g9uqA/5l8Mw7KEwvt48mYL8P2D8=; b=e7T5tf07aA5qIBTpxWmoXsh23Kv8gSdrvqk9wB9vzdDq+T4Pss308/Gbh91NH4vaPOxTAY +xOm6tPTcySWBxBkhbtHg+8HxPRNxXP7jDfBxrCpApATWt1ZWw0g/lmbx3U2Bf1ASrMRo0 e2TeH8cqjLQBAYrEq056dO+gq5tmnpTvHoZvN21WbAZbnlBiuI6PZnvyRlab4eZQzcgTu9 zktQKNwjjLwm/uuUx4gT+oNG0etTcf5nEMSdo9cT2wydB+MfSv3Ir6hYtoNgqOnlAmYnWP QrDq72Wh4j9GZbR67Ivjlh6p0+qzpuIz8/hPQHs93qr+yaIMdJ9I3T1ZitrPVA== Message-ID: <249e3cc4-440e-420d-8307-58b523edc7b0@postgresfriends.org> Date: Tue, 22 Jul 2025 17:14:33 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Proposal: QUALIFY clause To: Nico Williams , Tom Lane Cc: Merlin Moncure , Pavel Stehule , Matheus Alcantara , Pg Hackers , Peter Eisentraut References: <6c998e4f-f6f2-43c2-8b67-cfff360ef241@postgresfriends.org> <881159.1753161260@sss.pgh.pa.us> Content-Language: en-US From: Vik Fearing In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdejhedvfecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhepkfffgggfuffvvehfhfgjtgfgsehtkeertddtvdejnecuhfhrohhmpeggihhkucfhvggrrhhinhhguceovhhikhesphhoshhtghhrvghsfhhrihgvnhgushdrohhrgheqnecuggftrfgrthhtvghrnhepuddtveefleegvddutdejhffhleehhfevheeilefhgeettdeuhfdtffegvdfgteffnecukfhppedvrgdtvdemkeegvdekmeduudgvtdemvdejtddumegrgegvudemgedvfhegmegrlegrkeemkegvieeknecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepvdgrtddvmeekgedvkeemudduvgdtmedvjedtudemrgegvgdumeegvdhfgeemrgelrgekmeekvgeikedphhgvlhhopeglkffrggeimedvrgdtvdemkeegvdekmeduudgvtdemvdejtddumegrgegvudemgedvfhegmegrlegrkeemkegvieekngdpmhgrihhlfhhrohhmpehvihhksehpohhsthhgrhgvshhfrhhivghnughsrdhorhhgpdhnsggprhgtphhtthhopeejpdhrtghpthhtohepnhhitghosegtrhihphhtohhnvggtthhorhdrtghomhdprhgtphhtthhopehtghhlsehsshhsrdhpghhhrdhprgdruhhspdhrtghpthhtohepmhhmohhntghur hgvsehgmhgrihhlrdgtohhmpdhrtghpthhtohepphgrvhgvlhdrshhtvghhuhhlvgesghhmrghilhdrtghomhdprhgtphhtthhopehmrghthhgvuhhsshhsihhlvheljeesghhmrghilhdrtghomhdprhgtphhtthhopehpghhsqhhlqdhhrggtkhgvrhhssehpohhsthhgrhgvshhqlhdrohhrghdprhgtphhtthhopehpvghtvghrsegvihhsvghnthhrrghuthdrohhrgh X-GND-Sasl: vik@postgresfriends.org List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 22/07/2025 17:07, Nico Williams wrote: > On Tue, Jul 22, 2025 at 01:14:20AM -0400, Tom Lane wrote: >> 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). > Pavel doesn't say that window functions are aggregate functions. Pavel > said they are +/- (more or less, really, just similar to) aggregate > functions. There is a similarity. But I appreciate the point about > which passes get which, and that definitely makes the two-HAVING- > clauses concept much more unwieldy. Window functions and aggregates have only one thing in common, and that is that they can both operate on a window frame. Otherwise the difference is night and day.  Especially when you consider nested window clauses (that postgres does not support yet). > I agree that its own clause is best; I just greatly dislike QUALIFY. Sorry. -- Vik Fearing