Re: BUG #13336: Unexpected result from invalid query

Поиск
Список
Период
Сортировка
От Christian Ullrich
Тема Re: BUG #13336: Unexpected result from invalid query
Дата
Msg-id AM2PR06MB0690F494EDEBCDF868475B66D4CF0@AM2PR06MB0690.eurprd06.prod.outlook.com
обсуждение исходный текст
Ответ на Re: BUG #13336: Unexpected result from invalid query  (Andres Freund <andres@anarazel.de>)
Ответы Re: BUG #13336: Unexpected result from invalid query  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-bugs
* From: Andres Freund [mailto:andres@anarazel.de]

> On 2015-05-23 00:05:27 +0000, chris@chrullrich.net wrote:
> > -- Note: No column "foo" in test_table2
> > postgres=3D# select * from test_table where foo in (select foo from
> > test_table2);
> >  foo | bar
> > -----+-----
> >  one |   1
> >  two |   2
>=20
> That's not a bug. In a good number of subqueries you need access fields
> from the surrounding query.

Hm. That makes some sense, I guess. But is that true even if the reference =
in the subquery is not explicitly qualified? "SELECT foo FROM test_table2" =
looks to me like it refers to that table pretty unequivocally.

On the other hand I can find one sentence in the documentation on the subje=
ct, and it appears to support the conclusion that this is not a bug:

http://www.postgresql.org/docs/9.4/static/queries-table-expressions.html:

    Example: SELECT ... FROM fdt WHERE c1 IN (SELECT c3 FROM t2 WHERE c2 =3D f=
dt.c1 + 10)

    Qualifying c1 as fdt.c1 is only necessary if c1 is also the name of a=20
    column in the derived input table of the subquery.

That can be read as confirming that resolving the unqualified name against =
the outer query is intended.

Still seems weird to me. But if that' the way it is, I'm sorry for the nois=
e.

--=20
Christian

В списке pgsql-bugs по дате отправления:

Предыдущее
От: Andres Freund
Дата:
Сообщение: Re: BUG #13336: Unexpected result from invalid query
Следующее
От: Tom Lane
Дата:
Сообщение: Re: BUG #13336: Unexpected result from invalid query