Обсуждение: BUG #4742: wrong resultset instead of syntax error

Поиск
Список
Период
Сортировка

BUG #4742: wrong resultset instead of syntax error

От
"Slava Moudry"
Дата:
The following bug has been logged online:

Bug reference:      4742
Logged by:          Slava Moudry
Email address:      smoudry@4info.net
PostgreSQL version: 8.3.0
Operating system:   linux
Description:        wrong resultset instead of syntax error
Details:

I believe this is a parser error, it should fail rather than return all rows
from keyword since there is no keyword_id in carrier table. The same can be
illustrated with any other tables:

smslocate_edw=# select count(*) from keyword where keyword_id in (select
keyword_id from carrier)
smslocate_edw-# ;
 count
-------
 35749
(1 row)

smslocate_edw=# select keyword_id from carrier;

ERROR:  column "keyword_id" does not exist
LINE 1: select keyword_id from carrier;
               ^

Re: BUG #4742: wrong resultset instead of syntax error

От
Heikki Linnakangas
Дата:
Slava Moudry wrote:
> I believe this is a parser error, it should fail rather than return all rows
> from keyword since there is no keyword_id in carrier table. The same can be
> illustrated with any other tables:
>
> smslocate_edw=# select count(*) from keyword where keyword_id in (select
> keyword_id from carrier)

It's not a bug, although I admit I've done the same mistake myself many
times. keyword_id refers to keyword.keyword_id from the outer query in
this case. It makes sense if you think of a more complex query like:

select count(*) from keyword where keyword_ratio > (select keyword_id /
carrier_id from carrier)

If keyword_id wasn't allowed in the subquery, it would be impossible to
write more complex queries like that.

--
   Heikki Linnakangas
   EnterpriseDB   http://www.enterprisedb.com