Received: from sss.pgh.pa.us ([192.204.191.242]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f5PFaDa83610 for ; Mon, 25 Jun 2001 11:36:13 -0400 (EDT) (envelope-from tgl@sss.pgh.pa.us) 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 f5PFZs315867; Mon, 25 Jun 2001 11:35:54 -0400 (EDT) To: Weiping He cc: pgsql-docs@postgresql.org Subject: Re: doc question about column name alias In-reply-to: <3B374CF6.C1AB82F0@zhengmai.com.cn> References: <3B374CF6.C1AB82F0@zhengmai.com.cn> Comments: In-reply-to Weiping He message dated "Mon, 25 Jun 2001 22:38:46 +0800" Date: Mon, 25 Jun 2001 11:35:54 -0400 Message-ID: <15864.993483354@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200106/40 X-Sequence-Number: 838 Weiping He 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