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 1qe2Sr-005Yrw-Dh for pgsql-docs@arkaria.postgresql.org; Thu, 07 Sep 2023 00:01: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 1qe2Sp-00DzLy-T1 for pgsql-docs@arkaria.postgresql.org; Thu, 07 Sep 2023 00:01:39 +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 1qe2Sp-00DzLn-Kn for pgsql-docs@lists.postgresql.org; Thu, 07 Sep 2023 00:01:39 +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 1qe2Sm-0039Na-BT for pgsql-docs@lists.postgresql.org; Thu, 07 Sep 2023 00:01:38 +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 38701UBe1591986; Wed, 6 Sep 2023 20:01:30 -0400 From: Tom Lane To: Bruce Momjian cc: "David G. Johnston" , Laurenz Albe , postgres-hape@gmx.de, pgsql-docs@lists.postgresql.org Subject: Re: group by can use alias from select list In-reply-to: References: <168871536004.379168.9352636188330923805@wrigleys.postgresql.org> <25b70e6ec7bef81acac508dc61dfa01e72c96252.camel@cybertec.at> Comments: In-reply-to Bruce Momjian message dated "Wed, 06 Sep 2023 19:51:34 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1591984.1694044890.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 06 Sep 2023 20:01:30 -0400 Message-ID: <1591985.1694044890@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Bruce Momjian writes: > On Tue, Jul 11, 2023 at 07:31:26AM -0700, David G. Johnston wrote: >> I think the complaint is that someone seeing the behavior in the wild c= omes to >> this order-of-operations and doesn't see that the observed behavior is >> documented. > How is the attached patch? Maybe better "Although query output columns are nominally computed in the next step, they can also be referenced (by name or by ordinal number) as GROUP BY elements". You could go further and add "Such references cannot be parts of GROUP BY expressions, however." Not sure if we cover that explicitly anywhere else. regards, tom lane