Re: inconsistency in aliasing - Mailing list pgsql-general

From Daniel Verite
Subject Re: inconsistency in aliasing
Date
Msg-id 66444c23-faae-43e3-bc53-007c54d690f8@mm
Whole thread Raw
In response to Re: inconsistency in aliasing  (Reg Me Please <regmeplease@gmail.com>)
List pgsql-general
    Reg Me Please wrote:

> >    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,
>
> Looks and smells like a bug.

Read
 http://www.postgresql.org/docs/8.3/static/queries-order.html

<quote>
  The sort expression(s) can be any expression that would be valid in
the query's select list
</quote>

score+1 is not valid in the query's select list (as well as "score"
anyway)

<quote>
 For backwards compatibility with the SQL92 version of the standard, a
sort_expression can instead be the name or number of an output column
</quote>

so that's why "score" alone works in the order by, despite it not being
valid in the select list.

<quote>
 Note that an output column name has to stand alone, it's not allowed
as part of an expression
</quote>

Which looks like the very issue discussed here, and it just behaves as
documented.

 Best regards,
--
 Daniel
 PostgreSQL-powered mail user agent and storage:
http://www.manitou-mail.org

pgsql-general by date:

Previous
From: Emanuel Calvo Franco
Date:
Subject: Re: [ADMIN] Problem with pg_dump
Next
From: "Thom Brown"
Date:
Subject: Logging on Gentoo