Re: where cannot use alias name of column?

Поиск
Список
Период
Сортировка
От Peter Eisentraut
Тема Re: where cannot use alias name of column?
Дата
Msg-id Pine.LNX.4.30.0109131553390.680-100000@peter.localdomain
обсуждение исходный текст
Ответ на where cannot use alias name of column?  (Giorgio Volpe <giorgio.volpe@gtngroup.it>)
Список pgsql-general
Giorgio Volpe writes:

> May be it's my ignorance about sql ...
> but why cannot i use alias name of a column in a where clause?
>
> # select key as cc from mytable where cc > 0;
> ERROR:  Attribute 'cc' not found

The processing order of this command is, perhaps unintuitively, FROM ->
WHERE -> SELECT [-> ORDER BY].  The aliases introduced in the SELECT list
are not available in the WHERE expression (but they would be in the ORDER
BY list).  If you want to use an alias in the WHERE clause you have to
introduce it in the FROM clause, such as:

SELECT * FROM mytable AS myalias (xx, yy, zz) WHERE zz > 0;

This may or may not be actually useful in your case.

--
Peter Eisentraut   peter_e@gmx.net   http://funkturm.homeip.net/~peter


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

Предыдущее
От: "Thurstan R. McDougle"
Дата:
Сообщение: Re: count of occurences PLUS optimisation
Следующее
От: Martijn van Oosterhout
Дата:
Сообщение: Re: count of occurences PLUS optimisation