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

From: Jov <amutu(at)amutu(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-bugs <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #7899: allow key word as alias in subquery but Can't reference it in outer query
Date: 2013-02-22 14:39:55
Message-ID: CADyrUxPsp8+X4Lv-5wuicczNNtCb++fKopD0vTSNpDWShinh1w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

can we make a cross reference from doc 4.4.1(
http://www.postgresql.org/docs/devel/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS
)
to
doc 7.3.2 (
http://www.postgresql.org/docs/devel/static/queries-select-lists.html#QUERIES-COLUMN-LABELS
)
*to mention that “AS” can make a key word to be a identifier?*
I have read the doc 4.4.1 and can't find this info from there so I thin it
is a bug.

2013/2/22 Jov <amutu(at)amutu(dot)com>

> I have get the description of this behaviour from doc 7.3.2
>
> http://www.postgresql.org/docs/devel/static/queries-select-lists.html#QUERIES-COLUMN-LABELS
> .
>
> from the error message now,I think syntax error may emmit by the
> parser,parser error make it hard to get the really condition such as the
> second token ‘end’ is a select item from a select statement.
>
> thanks
>
> 2013/2/22 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
>
>> "=?ISO-8859-1?B?Sm92?=" <amutu(at)amutu(dot)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
>> .
>>
>>
>
>
> --
> Jov
> blog: http:amutu.com/blog <http://amutu.com/blog>
>

--
Jov
blog: http:amutu.com/blog <http://amutu.com/blog>

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2013-02-22 18:34:48 Re: new BUG: "postgresql 9.2.3: very long query time"
Previous Message Jov 2013-02-22 14:24:10 Re: BUG #7899: allow key word as alias in subquery but Can't reference it in outer query