pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jean-Luc Lachance <jllachan@nsd.ca>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-sql@postgresql.org
Subject: Re: Sort problem
Date: Tue, 26 Feb 2002 11:41:32 -0500
Message-ID: <3C7BBABC.AFB24FF4@nsd.ca> (raw)
References: <200202251946.g1PJkbn04775@candle.pha.pa.us>
	<3C7AB259.A66B2282@nsd.ca>
	<25157.1014678561@sss.pgh.pa.us>

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 <jllachan@nsd.ca> 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



view thread (9+ messages)

Message-ID: <3C7BBABC.AFB24FF4@nsd.ca>
Permalink:  ../3C7BBABC.AFB24FF4@nsd.ca/
Also on:    postgresql.org/message-id/3C7BBABC.AFB24FF4@nsd.ca

 · 

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: jllachan@nsd.ca, tgl@sss.pgh.pa.us
  Subject: Re: Sort problem
  In-Reply-To: <3C7BBABC.AFB24FF4@nsd.ca>

* 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