Re: Column alias in where clause?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Column alias in where clause?
Дата
Msg-id 20619.1218676915@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Column alias in where clause?  (Martijn van Oosterhout <kleptog@svana.org>)
Список pgsql-general
Martijn van Oosterhout <kleptog@svana.org> writes:
> You can't. Conceptually, the result of the SELECT is not visible until
> *after* the WHERE clause has executed, so having the where clause
> depend on the select won't work.

It's not only conceptual.  Consider

    SELECT 1/x FROM mytab WHERE x <> 0;

You'd be unhappy if this query failed with a divide-by-zero error
(and it would be a violation of the SQL spec, too).  So per spec,
the SELECT list must not be evaluated until after WHERE completes,
and that's why it's not reasonable for WHERE to refer to the
SELECT list.

(Now, we've kinda broken this rule by allowing GROUP BY to refer
to SELECT items, but that's a matter for another discussion.)

            regards, tom lane

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: automatic REINDEX-ing
Следующее
От: Tom Lane
Дата:
Сообщение: Re: In-place conversion of type bool