如您所见,在我的SQL请求中,我有一个子查询,返回一个字符串数组(
当然,我可以使用这样的代码,但我想知道第一个查询出现错误的原因。
varchar[]
)。 我正在尝试通过在ANY
命令中传递的此数组来过滤table_1
值。由于某种原因,我看到了以下错误:ERROR: operator does not exist: character varying = character varying[] No operator matches the given name and argument types. You might need to add explicit type casts.
table_1.column_a
和table_2.column_a
列的数据类型是varchar
。
PostgreSQL版本:11.4
我犯了什么错误?
select
table_1.*
from
table_1
where
table_1.column_a = any(
select
array_agg(table_2.column_a)
from
table_2
)
当然,我可以使用这样的代码,但我想知道第一个查询出现错误的原因。
select
table_1.*
from
table_1
where
table_1.column_a in(
select
table_2.column_a
from
table_2
)