Re: Alias in the HAVING clause

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Alias in the HAVING clause
Дата
Msg-id 20580.1210781150@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Alias in the HAVING clause  (Robert Treat <xzilla@users.sourceforge.net>)
Список pgsql-general
Robert Treat <xzilla@users.sourceforge.net> 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

В списке pgsql-general по дате отправления:

Предыдущее
От: Decibel!
Дата:
Сообщение: Re: Best approach for large table maintenance
Следующее
От: mailtolouis2020-postgres@yahoo.com
Дата:
Сообщение: postgres crash when select a record