Re: BUG #7899: allow key word as alias in subquery but Can't reference it in outer query - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #7899: allow key word as alias in subquery but Can't reference it in outer query
Date
Msg-id 27500.1361541116@sss.pgh.pa.us
Whole thread Raw
In response to BUG #7899: allow key word as alias in subquery but Can't reference it in outer query  ("Jov" <amutu@amutu.com>)
Responses Re: BUG #7899: allow key word as alias in subquery but Can't reference it in outer query  (Jov <amutu@amutu.com>)
List pgsql-bugs
"Jov" <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



pgsql-bugs by date:

Previous
From: "Jov"
Date:
Subject: BUG #7899: allow key word as alias in subquery but Can't reference it in outer query
Next
From: Jov
Date:
Subject: Re: BUG #7899: allow key word as alias in subquery but Can't reference it in outer query