Re: BUG #1265: sorting by (ORDER BY) result of an operation for names assigned by AS does not work - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #1265: sorting by (ORDER BY) result of an operation for names assigned by AS does not work
Date
Msg-id 11828.1095865474@sss.pgh.pa.us
Whole thread Raw
In response to BUG #1265: sorting by (ORDER BY) result of an operation for names assigned by AS does not work  ("PostgreSQL Bugs List" <pgsql-bugs@postgresql.org>)
List pgsql-bugs
"PostgreSQL Bugs List" <pgsql-bugs@postgresql.org> writes:
>  The query:
> SELECT id, lang as name, (SELECT lang FROM participants WHERE id =
> event.participant) as pname FROM event ORDER BY name || pname;
>  returns an error:
> ERROR: column "name" does not exist

It's not a bug.  Per
http://www.postgresql.org/docs/7.4/static/sql-select.html
under "ORDER BY Clause"

: expression can be the name or ordinal number of an output column (SELECT
: list item), or it can be an arbitrary expression formed from
: input-column values.

The ability to reference an output column in ORDER BY is actually a legacy
feature that was removed in the SQL99 spec.

            regards, tom lane

pgsql-bugs by date:

Previous
From: "PostgreSQL Bugs List"
Date:
Subject: BUG #1265: sorting by (ORDER BY) result of an operation for names assigned by AS does not work
Next
From: "Reuven M. Lerner"
Date:
Subject: Error with PostgreSQL 8.0 beta 2, in "make check" on Mac OS X (10.3.5)