Re: inconsistency in aliasing - Mailing list pgsql-hackers

From Jasen Betts
Subject Re: inconsistency in aliasing
Date
Msg-id gkn2qk$16m$3@reversiblemaps.ath.cx
Whole thread Raw
List pgsql-hackers
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.


pgsql-hackers by date:

Previous
From: Jasen Betts
Date:
Subject: Re: fire trigger for a row without update?
Next
From: "Merlin Moncure"
Date:
Subject: Re: fire trigger for a row without update?