Re: Use of HAVING (Select/Group By) on a output-name of an aggregate function causes SYNTAX ERROR

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Carlos Sotto Maior \(UOL\)" <csotto(at)uol(dot)com(dot)br>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: Use of HAVING (Select/Group By) on a output-name of an aggregate function causes SYNTAX ERROR
Date: 2021-01-30 22:46:29
Message-ID: 3011179.1612046789@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

"Carlos Sotto Maior \(UOL\)" <csotto(at)uol(dot)com(dot)br> writes:
> In other words: Postgresql is matching <HAVING> 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

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Carlos Sotto Maior (UOL) 2021-01-31 00:00:40 RE: Use of HAVING (Select/Group By) on a output-name of an aggregate function causes SYNTAX ERROR
Previous Message Carlos Sotto Maior (UOL) 2021-01-30 22:41:05 Use of HAVING (Select/Group By) on a output-name of an aggregate function causes SYNTAX ERROR