Re: Using column aliasses in the same query

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Using column aliasses in the same query
Дата
Msg-id 25012.1303056039@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Using column aliasses in the same query  ("Robert J.C. Ivens" <robert@roclasi.com>)
Ответы Re: Using column aliasses in the same query  (Tore Halvorsen <tore.halvorsen@gmail.com>)
Список pgsql-general
"Robert J.C. Ivens" <robert@roclasi.com> writes:
> I am not sure if there ever was a feature request for using defined
> column aliases in the rest of a query.

Yes, we've heard that before.  Many times.  It's not going to happen,
and here's why: it's flat out contrary to the SQL specification, as well
as to the basic intuitive semantics of SQL.  The SELECT list is supposed
to be evaluated as the last step of a query (well, last except for ORDER
BY, which is why there's an exception for that).  It's nonsensical for
WHERE etc to depend on the results of the SELECT list.

As an example of why this is important, consider

    SELECT x/y AS z FROM tab WHERE y <> 0

If the WHERE clause doesn't act before the SELECT list is computed,
the query is going to fail with divisions-by-zero, exactly what the
WHERE clause is trying to prevent.  So it'd be nonsensical to refer
to z in the WHERE clause.

            regards, tom lane

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

Предыдущее
От: "Robert J.C. Ivens"
Дата:
Сообщение: Re: Using column aliasses in the same query
Следующее
От: Alexander Farber
Дата:
Сообщение: Installing PGDG on a fresh CentOS 5.6