pg.ddx.io  pgsql-docs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Weiping He <laser@zhengmai.com.cn>
Cc: pgsql-docs@postgresql.org
Subject: Re: doc question about column name alias
Date: Mon, 25 Jun 2001 11:35:54 -0400
Message-ID: <15864.993483354@sss.pgh.pa.us> (raw)
In-Reply-To: <3B374CF6.C1AB82F0@zhengmai.com.cn>
References: <3B374CF6.C1AB82F0@zhengmai.com.cn>

Weiping He <laser@zhengmai.com.cn> writes:
> SELECT a AS b FROM table1 ORDER BY a;
> I think it should be:
> SELECT a AS b FROM table1 ORDER BY b;

You are correct that the latter is the SQL-standard version.  The former
is *also* accepted by Postgres --- but the point the text is trying to
make is that "ORDER BY a" is interpreted as a reference to the original
column "a", not to the output expression that happens to also reference
"a".  Perhaps this equivalent situation is a little more clear:

	SELECT a+b AS c FROM table1 ORDER BY a+b;
	SELECT a+b AS c FROM table1 ORDER BY c;

Both of these are accepted by Postgres; only the second one is SQL92;
the first one could cause a+b to be computed twice per row, the second
only once per row.  (I think that in fact the system will notice that
it has duplicate subexpressions here, but that's an optimization.)

Feel free to propose improved wording for the English docs ...

			regards, tom lane



view thread (5+ messages)  latest in thread

Message-ID: <15864.993483354@sss.pgh.pa.us>
Permalink:  ../15864.993483354@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/15864.993483354@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-docs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, laser@zhengmai.com.cn
  Subject: Re: doc question about column name alias
  In-Reply-To: <15864.993483354@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