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 1wjfgI-000ET1-1X for pgsql-hackers@arkaria.postgresql.org; Tue, 14 Jul 2026 16:08:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wjfgF-0043Aw-35 for pgsql-hackers@arkaria.postgresql.org; Tue, 14 Jul 2026 16:08:24 +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 1wjfgF-0043An-28 for pgsql-hackers@lists.postgresql.org; Tue, 14 Jul 2026 16:08:24 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wjfgE-00000000Cpi-2Ksr for pgsql-hackers@postgresql.org; Tue, 14 Jul 2026 16:08:24 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.18.1/8.18.1) with ESMTP id 66EG8KKO3338664; Tue, 14 Jul 2026 12:08:20 -0400 From: Tom Lane To: Daniel Gustafsson cc: Chao Li , PostgreSQL Hackers Subject: Re: Fix GROUP BY ALL handling of ORDER BY operator semantics In-reply-to: References: <5243308F-8E5C-45AA-828C-FAD96C4F34DA@gmail.com> <3278800.1783989856@sss.pgh.pa.us> Comments: In-reply-to Daniel Gustafsson message dated "Tue, 14 Jul 2026 16:01:34 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3338662.1784045300.1@sss.pgh.pa.us> Date: Tue, 14 Jul 2026 12:08:20 -0400 Message-ID: <3338663.1784045300@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Daniel Gustafsson writes: > Ack. Another case I am a bit confused by is: > postgres=# create table t (a integer); > CREATE TABLE > postgres=# select 1 as x from t group by (); > x > --- > 1 > (1 row) > postgres=# select 1 as x from t group by all; > x > --- > (0 rows) > Shouldn't those two queries yield the same result, or am I missing something > obvious? I might be undercaffeinated still, but I think those are both correct. "GROUP BY ()" has similar effects to use of an aggregate or HAVING clause: it forces the table scan's results to be combined into a single grouped row. But you get a grouped row even if the table is empty. The second case is equivalent to "select 1 as x from t group by x", and this is different because it will produce a grouped row only if the table isn't empty. (The fact that the grouping expression is a constant doesn't change the rule.) Not one of SQL's more consistent behaviors perhaps, but I believe it's all per spec. regards, tom lane