Robert Treat <xzilla@xxxxxxxxxxxxxxxxxxxxx> writes: > ... but I have to wonder, if we have established f1 by the time > we evaluate the group by, shouldn't we also be able to determine f1 at having > time, and therefore allow alias in having in this instance? The key point is that we only allow output-list aliases (in either GROUP BY or ORDER BY) as the *single* component of a grouping/ordering item --- that is, these are equivalent to the "ORDER BY 1" type of column-number shortcut. This provides useful functionality for grouping/ordering, but not so much for HAVING. As in the OP's example "HAVING f1 <> 0", you'd not be able to provide what is asked for unless you allow the aliases to be buried within expressions. And at that point you have got a really serious problem with ambiguity against column names that are exposed by the FROM clause. The long and the short of it is that allowing aliases in GROUP BY at all was a mistake, and we're not going to enlarge that mistake by the amount that would be needed to do what the OP asks. regards, tom lane