pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #7899: allow key word as alias in subquery but Can't reference it in outer query
5+ messages / 3 participants
[nested] [flat]

* BUG #7899: allow key word as alias in subquery but Can't reference it in outer query
@ 2013-02-22 01:50  amutu@amutu.com
  0 siblings, 0 replies; 5+ messages in thread

From: amutu@amutu.com @ 2013-02-22 01:50 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      7899
Logged by:          jov
Email address:      amutu@amutu.com
PostgreSQL version: 9.1.3
Operating system:   CentOS 6
Description:        

xxx=# select 2 from (select 1 as end) t;   
 ?column? 
----------
        2
(1 row)

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;
               ^

xxx=# select version();  
                                                   version                  
                               
  
------------------------------------------------------------------------------------------------------------
--
 PostgreSQL 9.1.3 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.4.5
20110214 (Red Hat 4.4.5-6), 64-bi
t
(1 row)

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. 




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



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* BUG #7899: allow key word as alias in subquery but Can't reference it in outer query
@ 2013-02-22 12:05  Jov <amutu@amutu.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Jov @ 2013-02-22 12:05 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      7899
Logged by:          jov
Email address:      amutu@amutu.com
PostgreSQL version: 9.1.3
Operating system:   CentOS 6
Description:        

xxx=# select 2 from (select 1 as end) t;   
 ?column? 
----------
        2
(1 row)

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;
               ^

xxx=# select version();  
                                                   version                  
                               
  
------------------------------------------------------------------------------------------------------------
--
 PostgreSQL 9.1.3 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.4.5
20110214 (Red Hat 4.4.5-6), 64-bi
t
(1 row)

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.

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: BUG #7899: allow key word as alias in subquery but Can't reference it in outer query
@ 2013-02-22 13:51  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Jov <amutu@amutu.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Tom Lane @ 2013-02-22 13:51 UTC (permalink / raw)
  To: Jov <amutu@amutu.com>; +Cc: pgsql-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



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: BUG #7899: allow key word as alias in subquery but Can't reference it in outer query
@ 2013-02-22 14:24  Jov <amutu@amutu.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 5+ messages in thread

From: Jov @ 2013-02-22 14:24 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-bugs

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@sss.pgh.pa.us>

> "=?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
> .
>
>


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

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: BUG #7899: allow key word as alias in subquery but Can't reference it in outer query
@ 2013-02-22 14:39  Jov <amutu@amutu.com>
  parent: Jov <amutu@amutu.com>
  0 siblings, 0 replies; 5+ messages in thread

From: Jov @ 2013-02-22 14:39 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: 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@amutu.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@sss.pgh.pa.us>
>
>> "=?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
>> .
>>
>>
>
>
> --
> Jov
> blog: http:amutu.com/blog <http://amutu.com/blog;
>



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

^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2013-02-22 14:39 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-02-22 01:50 BUG #7899: allow key word as alias in subquery but Can't reference it in outer query amutu@amutu.com
2013-02-22 12:05 BUG #7899: allow key word as alias in subquery but Can't reference it in outer query Jov <amutu@amutu.com>
2013-02-22 13:51 ` Tom Lane <tgl@sss.pgh.pa.us>
2013-02-22 14:24   ` Jov <amutu@amutu.com>
2013-02-22 14:39     ` Jov <amutu@amutu.com>

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