Re: Possible wrong result with some "in" subquery with non-existing columns

Поиск
Список
Период
Сортировка
От Xiong He
Тема Re: Possible wrong result with some "in" subquery with non-existing columns
Дата
Msg-id tencent_325E6E6DAA40616C4066A15F603DBAD0B205@qq.com
обсуждение исходный текст
Ответ на Re: Possible wrong result with some "in" subquery with non-existing columns  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: Possible wrong result with some "in" subquery with non-existing columns
Список pgsql-bugs
Thanks.  Tom.
I think it just makes sense. It doesn't matter if the user knows how to express the real query.
Possibly it's better to emphasize this scenario  as an example in the official document :-)

Regards,
Xiong


------------------ Original ------------------
From: "Tom Lane" <tgl@sss.pgh.pa.us>;
Date: Tue, Jan 17, 2023 04:04 PM
To: "Xiong He"<iihero@qq.com>;
Cc: "pgsql-bugs"<pgsql-bugs@lists.postgresql.org>;
Subject: Re: Possible wrong result with some "in" subquery with non-existing columns

"Xiong He" <iihero@qq.com> writes:
> mydb=# create table test1(id1 int primary key, col2 varchar(32));
> mydb=# create table test2(id2 int primary key, col2 varchar(32));
> mydb=# select * from test1 where id1 in (select id1 from test2 where id2 = 2);

> In the above query: id1 is not a column of table test2.

Nope, but it's a legal outer reference.

> Should not we expect this should be en error instead of it thinking it's a column from the table : test1?

This behavior is required by the SQL standard, and has been for
decades.  Yes, it trips up novices all the time, but it does
have valid use-cases.

regards, tom lane

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Possible wrong result with some "in" subquery with non-existing columns
Следующее
От: Amit Kapila
Дата:
Сообщение: Re: DROP DATABASE deadlocks with logical replication worker in PG 15.1