pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Michael Agbaglo <byteshifter@shifted-bytes.de>
Cc: pgsql-sql@postgresql.org
Subject: Re: syntax for access an alias in the where clause ?
Date: Wed, 19 Jun 2002 17:23:16 -0400
Message-ID: <7447.1024521796@sss.pgh.pa.us> (raw)
In-Reply-To: <3D10C770.7040100@shifted-bytes.de>
References: <3D10C770.7040100@shifted-bytes.de>

Michael Agbaglo <byteshifter@shifted-bytes.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



view thread (7+ messages)  latest in thread

Message-ID: <7447.1024521796@sss.pgh.pa.us>
Permalink:  ../7447.1024521796@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/7447.1024521796@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, byteshifter@shifted-bytes.de
  Subject: Re: syntax for access an alias in the where clause ?
  In-Reply-To: <7447.1024521796@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox