带有语法错误的 PostgreSQL 子查询给出了有效的结果 [英] PostgreSQL subquery with syntax error gives a valid result
本文介绍了带有语法错误的 PostgreSQL 子查询给出了有效的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这里发生了什么?
我有两个表,test1 和 test2:
I got two tables, test1 and test2:
create table test1 (id1 int4 primary key);
create table test2 (id2 int4 primary key);
正如预期的那样,这个查询:
As expected, this query:
select id1 from test2;
产生语法错误:
ERROR: column "id1" does not exist
LINE 1: select id1 from test2;
但是,当我尝试执行此查询时:
However, when I try to execute this query:
select * from test1 where id1 in (select id1 from test2);
PostgreSQL 不抱怨,执行查询并给我:
PostgreSQL doesn't complain, executes the query and gives me:
id1
-----
(0 rows)
这有什么逻辑吗?还是我应该提交错误报告?
Is there any logic in this? Or should I file a bug report?
推荐答案
来自外部 select
的列在子选择中可见.
Columns from outer select
are visible in sub-select.
您的查询相当于:
select *
from test1
where test1.id1 in (select test1.id1 from test2);
这篇关于带有语法错误的 PostgreSQL 子查询给出了有效的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文