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 1ueEb1-006iRG-1i for pgsql-hackers@arkaria.postgresql.org; Tue, 22 Jul 2025 15:07:59 +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 1ueEay-0095tK-Ez for pgsql-hackers@arkaria.postgresql.org; Tue, 22 Jul 2025 15:07:56 +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 1ueEax-0095tC-SS for pgsql-hackers@lists.postgresql.org; Tue, 22 Jul 2025 15:07:56 +0000 Received: from bumble.birch.relay.mailchannels.net ([23.83.209.25]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1ueEau-000FJU-1w for pgsql-hackers@postgresql.org; Tue, 22 Jul 2025 15:07:55 +0000 X-Sender-Id: dreamhost|x-authsender|nico@cryptonector.com Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 108898C4CCF; Tue, 22 Jul 2025 15:07:51 +0000 (UTC) Received: from pdx1-sub0-mail-a288.dreamhost.com (100-119-222-212.trex-nlb.outbound.svc.cluster.local [100.119.222.212]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 999A58C4AAD; Tue, 22 Jul 2025 15:07:50 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1753196870; a=rsa-sha256; cv=none; b=lm9hYRKPO9aZpoSAk/ap8yrZHPJ+eUTl8Fqt6DIbCm8JDFanIsqF/sovBkY7Bhml21oC6W D5dCycCQGm66J9rh2E8hQHMop1kDx6kIT7oWO2on8Ayx+Be32G0rdSfymR9uDASq2EGbGJ +Fa3LRrUnoa6XUkVk8RfVZzVMCw+xoyHTFJ8h+Ed8MXQ4z86fEeasQ6LbJFOPdCGd72r5n zIzP2yhCqeNoE045NsgnXRwCMD5Emkv0ObrnJB9m+Dg+yIY33KHKFjLJlpYEEPQHXpiX3g Vvtih/RqHGXdiSiBnzthd/CDsRrgsIlVKstB8vjJTd7/p22xYekAFhd8HGjuhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1753196870; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=nBp4QnmlnqT75Ele3BX5BB/8la4aM20JQc8CDeBnqFk=; b=Ecuc/dr21d5WTc0xJRFkRbg4qfToF+nuKl1cTJTRgWPVlAN9wOnvqt3o0fLYggnq4CWLLm 97aqjq6j49pzpNJVDlYzFHlFVTCB5+fReHb11ANRyYLUX+KdNAoaKidWttDbXJoOdNVWwL kJOee3A0qZu/N2YgLlbLVHx2UaGnD76d53IxC8ifcUoO+OJUj6OlX22mHpeGgu1bzoAtWK 5gQNE7S4gFwl1QsDVFesIYhhRtyIvAWcQoBT3LivkuSqiOZOOKgL3hm2GPRLCP0U/qm31h Sv0eVELae7yd5JoXNZ6pgU4dGUU9hIBVsnYOQTCnU87JAhVBNgzLevAK4OGedA== ARC-Authentication-Results: i=1; rspamd-7df5bc8bc6-pdbrn; auth=pass smtp.auth=dreamhost smtp.mailfrom=nico@cryptonector.com X-Sender-Id: dreamhost|x-authsender|nico@cryptonector.com X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|nico@cryptonector.com X-MailChannels-Auth-Id: dreamhost X-Fearful-Eyes: 75ba65972550c0f5_1753196870893_4290859936 X-MC-Loop-Signature: 1753196870893:17513718 X-MC-Ingress-Time: 1753196870893 Received: from pdx1-sub0-mail-a288.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.119.222.212 (trex/7.1.3); Tue, 22 Jul 2025 15:07:50 +0000 Received: from ubby (syn-075-081-095-064.res.spectrum.com [75.81.95.64]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: nico@cryptonector.com) by pdx1-sub0-mail-a288.dreamhost.com (Postfix) with ESMTPSA id 4bmgcP5DVZz2g; Tue, 22 Jul 2025 08:07:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cryptonector.com; s=dreamhost; t=1753196870; bh=nBp4QnmlnqT75Ele3BX5BB/8la4aM20JQc8CDeBnqFk=; h=Date:From:To:Cc:Subject:Content-Type; b=njWBZsJTitIoZUYT4l9vo5bo/oPvj1oeLh/erRG9ev3Xhq+1D0D1W0nayZDQ7a5GN k4OidZXShfruwQC++elzVBa+8JdSez7LbKxq/mHBpXou/FVSKmZUHb91vzdi+xkuAU dHZUUdJnkzouydlF1peYp0mp0IOdJXYIrhobEAHdDB12TrScVZyc1Bw8b9hAAs+LKD 7Cc4yBV0naBkWWQXbAav9jWwNxTFPY+s0TXe/BTJQvaUbfWmqHU02nUWB9Cq2UubPQ X+Qvf8vMCOBjjc4QwbXytui0lw0lJMPOSX6BtSvMOHK/TyGij1lO/NllXaDEK7xr54 29RSNFigRjOaw== Date: Tue, 22 Jul 2025 10:07:47 -0500 From: Nico Williams To: Tom Lane Cc: Merlin Moncure , Pavel Stehule , Vik Fearing , Matheus Alcantara , Pg Hackers , Peter Eisentraut Subject: Re: Proposal: QUALIFY clause Message-ID: References: <6c998e4f-f6f2-43c2-8b67-cfff360ef241@postgresfriends.org> <881159.1753161260@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <881159.1753161260@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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. > If we're going to support this, it does need to be its own clause. I agree that its own clause is best; I just greatly dislike QUALIFY.