Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l5z0k-00059o-Vv for pgsql-bugs@arkaria.postgresql.org; Sat, 30 Jan 2021 22:46:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l5z0j-0001hb-Sz for pgsql-bugs@arkaria.postgresql.org; Sat, 30 Jan 2021 22:46:33 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l5z0j-0001hN-MY for pgsql-bugs@lists.postgresql.org; Sat, 30 Jan 2021 22:46:33 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l5z0h-0003gP-N7 for pgsql-bugs@lists.postgresql.org; Sat, 30 Jan 2021 22:46:33 +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 10UMkTtl3011180; Sat, 30 Jan 2021 17:46:29 -0500 From: Tom Lane To: "Carlos Sotto Maior \(UOL\)" cc: pgsql-bugs@lists.postgresql.org Subject: Re: Use of HAVING (Select/Group By) on a output-name of an aggregate function causes SYNTAX ERROR In-reply-to: <01ca01d6f759$00c24510$0246cf30$@uol.com.br> References: <01ca01d6f759$00c24510$0246cf30$@uol.com.br> Comments: In-reply-to "Carlos Sotto Maior \(UOL\)" message dated "Sat, 30 Jan 2021 19:41:05 -0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3011178.1612046789.1@sss.pgh.pa.us> Date: Sat, 30 Jan 2021 17:46:29 -0500 Message-ID: <3011179.1612046789@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk "Carlos Sotto Maior \(UOL\)" writes: > In other words: Postgresql is matching arguments to columns at > table level instead of matching to a group by result level. That's per SQL standard. The fact that we allow the case in GROUP BY is an anachronism. (You'll find also that we only allow it for GROUP BY items that are *just* an output column name, not any more-complicated expression. The equivalent restriction for HAVING would make such a feature near useless anyway.) regards, tom lane