Re: Sort problem

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Sort problem
Дата
Msg-id 25157.1014678561@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Sort problem  (Jean-Luc Lachance <jllachan@nsd.ca>)
Список pgsql-sql
Jean-Luc Lachance <jllachan@nsd.ca> writes:
> Can someone (Tom maybe) please tell me why one can not use an alias from
> the select list in the where clause or the order by clause.

Eh?  You can do it in the ORDER BY clause:

regression=# select f1 as alias from int4_tbl order by alias;   alias
--------------2147483647-2147483647    -123456    -123456          0          0     123456     123456 2147483647
2147483647
(10 rows)

As for WHERE, the reason you can't do it there is that it wouldn't be
meaningful.  The SELECT list is not calculated until *after* the WHERE
conditions are applied.  Any SQL book should tell you about the stages
of processing of a SELECT query...
        regards, tom lane


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

Предыдущее
От: "Dan Langille"
Дата:
Сообщение: record iteration within SQL
Следующее
От: Tom Lane
Дата:
Сообщение: Re: record iteration within SQL