这里发生了什么?
我有两个表,test1 和 test2:
create table test1 (id1 int4 primary key);
create table test2 (id2 int4 primary key);
正如预期的那样,这个查询:
select id1 from test2;
产生语法错误:
ERROR: column "id1" does not exist
LINE 1: select id1 from test2;
但是,当我尝试执行此查询时:
select * from test1 where id1 in (select id1 from test2);
PostgreSQL 没有提示,执行查询并给我:
id1
-----
(0 rows)
这有逻辑吗?还是我应该提交错误报告?
最佳答案
来自外部 select
的列在子选择中可见。
您的查询等同于:
select *
from test1
where test1.id1 in (select test1.id1 from test2);
关于sql - 具有语法错误的 PostgreSQL 子查询给出了有效结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46215082/