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.96) (envelope-from ) id 1wCbpt-0029gO-2J for pgsql-hackers@arkaria.postgresql.org; Tue, 14 Apr 2026 11:21:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wCbpr-00BUG6-1p for pgsql-hackers@arkaria.postgresql.org; Tue, 14 Apr 2026 11:21:40 +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.96) (envelope-from ) id 1wCbpq-00BUFw-1u for pgsql-hackers@lists.postgresql.org; Tue, 14 Apr 2026 11:21:40 +0000 Received: from fhigh-a2-smtp.messagingengine.com ([103.168.172.153]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wCbpn-000000010xM-39z4 for pgsql-hackers@postgresql.org; Tue, 14 Apr 2026 11:21:39 +0000 Received: from phl-compute-08.internal (phl-compute-08.internal [10.202.2.48]) by mailfhigh.phl.internal (Postfix) with ESMTP id 2DA0E140005E; Tue, 14 Apr 2026 07:21:33 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Tue, 14 Apr 2026 07:21:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eisentraut.org; h=cc:cc:content-transfer-encoding:content-type:content-type :date:date:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:subject:subject:to:to; s=fm1; t=1776165693; x=1776252093; bh=9f//H9paJAd4pp9kI6AGz5E+YfNUlJdU RFK1O/XrJDw=; b=JdhBepFmZc9BFZ30IeV2FqFpXDNGD6+y9ge0HPtpX6ZFRthA eYVnsrwXkQLz0/5xIuFP+WUJy8r1TiKdjVSM9bqXuJbxoXnS3/jhodsKZRyTPuIF 8ZUBDTaWcgzr55UdTmOv6mAhMCt8JyFfsn6jlHLq9EJcp90qN2c/jwcBKpylrLml Yb42zrZ7QR9Ld+GD0pCDJnH4b4wTsryvII9vmqe1yTk0EPcOUqDi9GB5bgchUhgh yVoYlS7JFOflJugXB1A5sj2dBPiO3ACHqY4MBamgCBWufUXX7lxrx7szu5SuPU8H aMakbGCbv5QsWOYcPyVbgggPkv8CoqVjDhD5Zg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1776165693; x= 1776252093; bh=9f//H9paJAd4pp9kI6AGz5E+YfNUlJdURFK1O/XrJDw=; b=R gk8XokghHWp68xiGjg2Mi/SrOyDx0/W8+gMOA4p1oiUi+uZgZgKCQF6YK4d3K3wB AorHVYl+bp888gGPluV+HQJsOqlWbHmBIgOWkB6JkpriNzCPlwJSRysXxlg2RUD3 nc0R6Tmui3uR+RVgjkuhgkLBQxsMrdHXYIKKfYe96xEKVPRYM4pvwvmwIOTrqs3T r+0HbyWgkbe8jqmDLG+FIR2MMRxh5l5TGiITsG8RYyu7X72TuhTFmRG3NeITJHpk 62R5pixNwqOF44nzCcbrsrB2r80Q2ggEZxoHz8S2cK+NeXzb5eBy513Cyt8ancch k9EFdMppr07VXtr7Qa2nA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefhedrtddtgdeguddtvdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpefkffggfgfuhffvvehfjggtgfesthekredttddvjeenucfhrhhomheprfgvthgvrhcu gfhishgvnhhtrhgruhhtuceophgvthgvrhesvghishgvnhhtrhgruhhtrdhorhhgqeenuc ggtffrrghtthgvrhhnpeejgedvgffgfffguddtheegvefhgeeulefgleetteevtedvveet ledvfefhveefgfenucffohhmrghinhepphhoshhtghhrvghsqhhlrdhorhhgnecuvehluh hsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphgvthgvrhesvghi shgvnhhtrhgruhhtrdhorhhgpdhnsggprhgtphhtthhopeehpdhmohguvgepshhmthhpoh huthdprhgtphhtthhopehtghhlsehsshhsrdhpghhhrdhprgdruhhspdhrtghpthhtohep phhgshhqlhdqhhgrtghkvghrshesphhoshhtghhrvghsqhhlrdhorhhgpdhrtghpthhtoh epuggrvhhiugdrghdrjhhohhhnshhtohhnsehgmhgrihhlrdgtohhmpdhrtghpthhtohep uggrvhhiugesphhgghhurhhurdhnvghtpdhrtghpthhtohepphhoshhtghhrvghssehjvg hlthgvfhdrnhhl X-ME-Proxy: Feedback-ID: ie0a040ee:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 14 Apr 2026 07:21:31 -0400 (EDT) Message-ID: <49d5cbd1-7e47-4740-bc81-e574150f44cb@eisentraut.org> Date: Tue, 14 Apr 2026 13:21:30 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] GROUP BY ALL From: Peter Eisentraut To: Tom Lane Cc: pgsql-hackers , "David G. Johnston" , David Christensen , Jelte Fennema-Nio References: <931747.1721687375@sss.pgh.pa.us> <634aca95-6db5-4beb-b18d-67e65582817f@eisentraut.org> <4054709.1758895915@sss.pgh.pa.us> <3d01eb20-d587-4dec-9261-0c92240ce546@eisentraut.org> <4174779.1758917912@sss.pgh.pa.us> <87b40ca1-f935-4d71-9edb-9d9f1053cb45@eisentraut.org> Content-Language: en-US In-Reply-To: <87b40ca1-f935-4d71-9edb-9d9f1053cb45@eisentraut.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 27.09.25 15:30, Peter Eisentraut wrote: >> Also, what about window functions in the tlist? > >> (I didn't stop to figure out why this isn't giving the same error, but >> maybe it's an order-of-checks thing.)  In any case: should this give >> "window functions are not allowed in GROUP BY", or should the >> window-function-containing tlist item be silently skipped by GROUP BY >> ALL?  Trying to make it work is surely not the right answer. > > Hmm, I don't know.  The syntactic transformation talks about select list > elements that "do not directly contain an ", but > that can also appear as part of , so the syntactic > transformation might appear to apply only to some types of window > functions, which doesn't make sense to me. > > I don't know what a sensible behavior should be here.  Maybe in this > first patch version just reject use of GROUP BY ALL if you find any > window functions in the select list. The handling of window functions by GROUP BY ALL is a semi-open-item. The code in transformGroupClause() currently says: /* * Likewise, TLEs containing window functions are not okay to add * to GROUP BY. At this writing, the SQL standard is silent on * what to do with them, but by analogy to aggregates we'll just * skip them. */ if (pstate->p_hasWindowFuncs && contain_windowfuncs((Node *) tle->expr)) continue; The wording of the SQL standard currently does not address that at all (but we could fix it), which would mean that a window function ends up in the GROUP BY ALL expansion by default. Personally, I don't understand what the meaning of this should be. Aggregates relate to grouping, but window functions are a different processing phase, so that do they have to do with grouping? I don't see any mention of using GROUP BY with window functions in our relevant documentation, for example https://www.postgresql.org/docs/devel/sql-expressions.html#SYNTAX-WINDOW-FUNCTIONS https://www.postgresql.org/docs/devel/functions-window.html Commit ef38a4d9756 added a regression test EXPLAIN (COSTS OFF) SELECT a, COUNT(a) OVER (PARTITION BY a) FROM t1 GROUP BY ALL; but the test table contains no data, so I don't know if this kind of query produces interesting information. Wouldn't a more practical query use different columns, like SELECT a, COUNT(b) OVER (PARTITION BY a) FROM t1 ? I see that DuckDB and Oracle (the two other implementations that can be accessed relatively freely, though there are others) each behave differently here. Maybe we can produce some more test cases to see what useful behaviors should be?