pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Jov <amutu@amutu.com>
Cc: pgsql-bugs <pgsql-bugs@postgresql.org>
Subject: Re: BUG #7899: allow key word as alias in subquery but Can't reference it in outer query
Date: Fri, 22 Feb 2013 08:51:56 -0500
Message-ID: <27500.1361541116@sss.pgh.pa.us> (raw)
In-Reply-To: <tencent_0D5000710AA6BD14684FF659@qq.com>
References: <tencent_0D5000710AA6BD14684FF659@qq.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

"=?ISO-8859-1?B?Sm92?=" <amutu@amutu.com> writes:
> xxx=# select end from (select 1 as end) t;
> ERROR:  syntax error at or near "end"
> LINE 1: select end from (select 1 as end) t;
>                ^

You need to double-quote the outer use of "end", viz

regression=# select "end" from (select 1 as end) t;
 end 
-----
   1
(1 row)

In the context with "as", Postgres can tell the word is meant as a
column identifier not a keyword, but there's no way for it to know that
in the outer usage.

> I think use key word as alias should get a error message such as $key_word
> is Key Word,should not be used as identifier bla bla,so for some complex
> query error user can save a lot of time.

Well, yours is the first complaint we've ever had in that direction,
whereas we used to get a lot of complaints in the opposite direction,
back when we didn't allow keywords to be used for column names.
So I doubt we'll change it.  It is an interesting gotcha though :-(

			regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (5+ messages)  latest in thread

Message-ID: <27500.1361541116@sss.pgh.pa.us>
Permalink:  ../27500.1361541116@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/27500.1361541116@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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, amutu@amutu.com
  Subject: Re: BUG #7899: allow key word as alias in subquery but Can't reference it in outer query
  In-Reply-To: <27500.1361541116@sss.pgh.pa.us>
  References: <tencent_0D5000710AA6BD14684FF659@qq.com> <27500.1361541116@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