本文介绍了带有语法错误的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 *
from test1
where test1.id1 in (select test1.id1 from test2);

这篇关于带有语法错误的PostgreSQL子查询给出了有效的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-25 04:31