From: Tom Lane <tgl@sss.pgh.pa.us>
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
Date: Tue, 17 Jan 2023 03:04:18 -0500
Message-ID: <2915686.1673942658@sss.pgh.pa.us> (raw)
In-Reply-To: <tencent_E8F863DB3246FD47EBEE85FFF5E56B020508@qq.com>
References: <tencent_E8F863DB3246FD47EBEE85FFF5E56B020508@qq.com>
"=?ISO-8859-1?B?WGlvbmcgSGU=?=" <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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, iihero@qq.com, pgsql-bugs@lists.postgresql.org
Subject: Re: Possible wrong result with some "in" subquery with non-existing columns
In-Reply-To: <2915686.1673942658@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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