Re: Understanding Aliases

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Stanislav Raskin" <sr(at)brainswell(dot)de>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Understanding Aliases
Date: 2007-12-11 15:27:49
Message-ID: 14378.1197386869@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Stanislav Raskin" <sr(at)brainswell(dot)de> writes:
> Still no Idea why it does not work with the alias.

SELECT-list output aliases name the *output* columns of the SELECT.
Those output columns are not available to the SELECT's computation
clauses. Otherwise you'd have a logical circularity --- by definition,
the output row(s) can't have been computed yet when you're evaluating
a WHERE condition.

People frequently think that because ORDER BY can refer to the
output-column aliases, other clauses should be able to do it too,
but this is not so. Conceptually, ORDER BY happens after computation
of the output rows, so there's no logical inconsistency in allowing
it to do that ... but it's certainly confused enough people that
one wonders whether the SQL committee shouldn't have left that wart
out of the language.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Mason Hale 2007-12-11 15:37:28 Re: partitioned table query question
Previous Message A. Kretschmer 2007-12-11 15:24:10 Re: Hijack!