Re: syntax for access an alias in the where clause ?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Michael Agbaglo <byteshifter(at)shifted-bytes(dot)de>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: syntax for access an alias in the where clause ?
Date: 2002-06-19 21:23:16
Message-ID: 7447.1024521796@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Michael Agbaglo <byteshifter(at)shifted-bytes(dot)de> writes:
> select [expression 1] as [alias 1], [expression 2] as [alias 2]
> where [alias 1] < [alias 2]
> order by [alias 2] - [alias 1]
> ---> ERROR: Attribute '[alias 1]' not found
> I found a lot of 'select [expression] as' but I've never seen somebody
> accessing the alias ... Can't this be done ?

No, it can't, and the reason is that the WHERE clause is logically
evaluated before the SELECT list is (in fact, the SELECT list will
never be evaluated at rows where the WHERE clause returns false).
It would be circular to refer to SELECT outputs in WHERE.

regards, tom lane

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Jeff Eckermann 2002-06-19 22:04:27 Re: syntax for access an alias in the where clause ?
Previous Message Tom Lane 2002-06-19 21:19:31 Re: Tagging rows into collections?