Received: from beamish.nsd.ca (unknown [205.150.156.194]) by postgresql.org (Postfix) with ESMTP id DD8554767FE for ; Tue, 26 Feb 2002 11:31:10 -0500 (EST) Received: (from smap@localhost) by beamish.nsd.ca (8.9.3/8.9.3) id LAA10770; Tue, 26 Feb 2002 11:31:15 -0500 X-Authentication-Warning: beamish.nsd.ca: smap set sender to using -f Received: from reddog.nsd.ca(192.168.101.30) by beamish.nsd.ca via smap (V2.1/2.1+anti-relay+anti-spam) id xma010768; Tue, 26 Feb 02 11:30:57 -0500 Received: from nsd.ca (jllachan-linux.nsd.ca [192.168.101.148]) by reddog.nsd.ca (8.8.7/8.8.7) with ESMTP id LAA06392; Tue, 26 Feb 2002 11:32:52 -0500 Message-ID: <3C7BBABC.AFB24FF4@nsd.ca> Date: Tue, 26 Feb 2002 11:41:32 -0500 From: Jean-Luc Lachance X-Mailer: Mozilla 4.77 [en] (X11; U; Linux 2.4.9-12 i686) X-Accept-Language: en MIME-Version: 1.0 To: Tom Lane Cc: pgsql-sql@postgresql.org Subject: Re: Sort problem References: <200202251946.g1PJkbn04775@candle.pha.pa.us> <3C7AB259.A66B2282@nsd.ca> <25157.1014678561@sss.pgh.pa.us> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Archive-Number: 200202/399 X-Sequence-Number: 6821 Tom, You are right about the ORDER BY CLAUSE, but the parser should be able to rewrite the query so that I do not have to retype the whole thing... Tom Lane wrote: > > 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