Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id BA5A24761F9 for ; Mon, 25 Feb 2002 18:09:55 -0500 (EST) 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 g1PN9LS25160; Mon, 25 Feb 2002 18:09:21 -0500 (EST) To: Jean-Luc Lachance Cc: pgsql-sql@postgresql.org Subject: Re: Sort problem In-reply-to: <3C7AB259.A66B2282@nsd.ca> References: <200202251946.g1PJkbn04775@candle.pha.pa.us> <3C7AB259.A66B2282@nsd.ca> Comments: In-reply-to Jean-Luc Lachance message dated "Mon, 25 Feb 2002 16:53:29 -0500" Date: Mon, 25 Feb 2002 18:09:21 -0500 Message-ID: <25157.1014678561@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200202/372 X-Sequence-Number: 6794 Jean-Luc Lachance writes: > Can someone (Tom maybe) please tell me why one can not use an alias from > the select list in the where clause or the order by clause. Eh? You can do it in the ORDER BY clause: regression=# select f1 as alias from int4_tbl order by alias; alias ------------- -2147483647 -2147483647 -123456 -123456 0 0 123456 123456 2147483647 2147483647 (10 rows) As for WHERE, the reason you can't do it there is that it wouldn't be meaningful. The SELECT list is not calculated until *after* the WHERE conditions are applied. Any SQL book should tell you about the stages of processing of a SELECT query... regards, tom lane