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

From: "Carlos Sotto Maior (UOL)" <csotto(at)uol(dot)com(dot)br>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
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-31 00:00:40
Message-ID: 6015f32810472_761d2ac39d33710c286fd@ip-10-81-19-78.ec2.internal.mail
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Thanks a lot Tom.<br />
I&#39;ll solve it with a subquery.
<p>Carlos Sotto Maior (UOL)<br />
<a href="mailto:csotto(at)uol(dot)com(dot)br">csotto(at)uol(dot)com(dot)br</a></p>

<p>&nbsp;</p>
&nbsp;

<hr />
<div><br />
<strong>De: </strong>&quot;Tom Lane&quot; &lt;tgl(at)sss(dot)pgh(dot)pa(dot)us&gt;<br />
<strong>Enviada: </strong>2021/01/30 19:46:37<br />
<strong>Para: </strong>csotto(at)uol(dot)com(dot)br<br />
<strong>Cc: </strong> pgsql-bugs(at)lists(dot)postgresql(dot)org<br />
<strong>Assunto: </strong> Re: Use of HAVING (Select/Group By) on a output-name of an aggregate function causes SYNTAX ERROR<br />
&nbsp;</div>
&quot;Carlos Sotto Maior \(UOL\)&quot; &lt;csotto(at)uol(dot)com(dot)br&gt; writes:<br />
&gt; In other words: Postgresql is matching &lt;HAVING&gt; arguments to columns at<br />
&gt; table level instead of matching to a group by result level.<br />
<br />
That&#39;s per SQL standard. The fact that we allow the case in<br />
GROUP BY is an anachronism. (You&#39;ll find also that we only allow it<br />
for GROUP BY items that are *just* an output column name, not any<br />
more-complicated <span>expression</span>. The equivalent restriction for HAVING<br />
would make such a feature near useless anyway.)<br />
<br />
regards, tom lane

Attachment Content-Type Size
unknown_filename text/html 1.2 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2021-01-31 09:09:49 BUG #16846: "retrieved too many tuples in a bounded sort"
Previous Message Tom Lane 2021-01-30 22:46:29 Re: Use of HAVING (Select/Group By) on a output-name of an aggregate function causes SYNTAX ERROR