Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id A97A74761DF for ; Wed, 19 Jun 2002 18:04:34 -0400 (EDT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id 95753475AAC for ; Wed, 19 Jun 2002 17:58:11 -0400 (EDT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.11.4/8.11.4) with ESMTP id g5JLNG107450; Wed, 19 Jun 2002 17:23:16 -0400 (EDT) To: Michael Agbaglo Cc: pgsql-sql@postgresql.org Subject: Re: syntax for access an alias in the where clause ? In-reply-to: <3D10C770.7040100@shifted-bytes.de> References: <3D10C770.7040100@shifted-bytes.de> Comments: In-reply-to Michael Agbaglo message dated "Wed, 19 Jun 2002 20:03:28 +0200" Date: Wed, 19 Jun 2002 17:23:16 -0400 Message-ID: <7447.1024521796@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200206/260 X-Sequence-Number: 8225 Michael Agbaglo 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