Re: Using column aliasses in the same query - Mailing list pgsql-general

From Tom Lane
Subject Re: Using column aliasses in the same query
Date
Msg-id 25012.1303056039@sss.pgh.pa.us
Whole thread Raw
In response to Using column aliasses in the same query  ("Robert J.C. Ivens" <robert@roclasi.com>)
Responses Re: Using column aliasses in the same query
List pgsql-general
"Robert J.C. Ivens" <robert@roclasi.com> writes:
> I am not sure if there ever was a feature request for using defined
> column aliases in the rest of a query.

Yes, we've heard that before.  Many times.  It's not going to happen,
and here's why: it's flat out contrary to the SQL specification, as well
as to the basic intuitive semantics of SQL.  The SELECT list is supposed
to be evaluated as the last step of a query (well, last except for ORDER
BY, which is why there's an exception for that).  It's nonsensical for
WHERE etc to depend on the results of the SELECT list.

As an example of why this is important, consider

    SELECT x/y AS z FROM tab WHERE y <> 0

If the WHERE clause doesn't act before the SELECT list is computed,
the query is going to fail with divisions-by-zero, exactly what the
WHERE clause is trying to prevent.  So it'd be nonsensical to refer
to z in the WHERE clause.

            regards, tom lane

pgsql-general by date:

Previous
From: "Robert J.C. Ivens"
Date:
Subject: Re: Using column aliasses in the same query
Next
From: Alexander Farber
Date:
Subject: Installing PGDG on a fresh CentOS 5.6