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 1sW1kx-00CrOs-Ji for pgsql-hackers@arkaria.postgresql.org; Mon, 22 Jul 2024 22:43:47 +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 1sW1kv-007gnc-7K for pgsql-hackers@arkaria.postgresql.org; Mon, 22 Jul 2024 22:43:45 +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 1sW1ku-007gm1-Tr for pgsql-hackers@lists.postgresql.org; Mon, 22 Jul 2024 22:43:45 +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.94.2) (envelope-from ) id 1sW1ks-000w8y-Rl for pgsql-hackers@postgresql.org; Mon, 22 Jul 2024 22:43:44 +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 46MMhfax932964; Mon, 22 Jul 2024 18:43:41 -0400 From: Tom Lane To: Isaac Morland cc: "David G. Johnston" , David Christensen , pgsql-hackers Subject: Re: [PATCH] GROUP BY ALL In-reply-to: References: Comments: In-reply-to Isaac Morland message dated "Mon, 22 Jul 2024 17:40:55 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <932962.1721688221.1@sss.pgh.pa.us> Date: Mon, 22 Jul 2024 18:43:41 -0400 Message-ID: <932963.1721688221@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Isaac Morland writes: > And for when this might be useful, the syntax for it already exists, > although a spurious error message is generated: > odyssey=> select (uw_term).*, count(*) from uw_term group by uw_term; > ERROR: column "uw_term.term_id" must appear in the GROUP BY clause or be > used in an aggregate function > LINE 1: select (uw_term).*, count(*) from uw_term group by uw_term; > ^ > I'm not sure exactly what's going on here The SELECT entry is expanded into "uw_term.col1, uw_term.col2, uw_term.col3, ...", and those single-column Vars don't match the whole-row Var appearing in the GROUP BY list. I guess if we think this is important, we could add a proof rule saying that a per-column Var is functionally dependent on a whole-row Var of the same relation. Odd that the point hasn't come up before (though I guess that suggests that few people try this). regards, tom lane