From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Weiping He <laser(at)zhengmai(dot)com(dot)cn> |
Cc: | pgsql-docs(at)postgresql(dot)org |
Subject: | Re: doc question about column name alias |
Date: | 2001-06-25 15:35:54 |
Message-ID: | 15864.993483354@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-docs |
Weiping He <laser(at)zhengmai(dot)com(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Ivar Helbekkmo | 2001-06-26 15:25:14 | Re: doc question about column name alias |
Previous Message | Bruce Momjian | 2001-06-25 15:06:19 | Re: doc question about column name alias |