"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