Обсуждение: Re: inconsistency in aliasing

Поиск
Список
Период
Сортировка

Re: inconsistency in aliasing

От
Jasen Betts
Дата:
On 2009-01-14, Louis-David Mitterrand <vindex+lists-pgsql-general@apartia.org> wrote:
> Hi,
>
> This works:
>
>     critik=# select current_timestamp::abstime::int4 as score order by score;
>
> This doesn't:
>
>     critik=# select current_timestamp::abstime::int4 as score order by score + 1;  
>     ERROR:  column "score" does not exist
>     LINE 1: ...urrent_timestamp::abstime::int4 as score order by score + 1 ...
>
> Any idea ?
>
> Thanks,

if you really want to do that you can use a subselect,

select score from ( select current_timestamp::abstime::int4 as score )
as foo order by score+1;

but the demonstration is more interesting when the query returns several rows
and the expression changes the order.

select score from ( select generate_series(1,10) as score ) as foo
order by score % 2 desc; -- odds and evens.

:)

bye.