最近我读了Quantified Comparison Predicates – Some SQL's Rarest Species:
事实上,SQL 标准将IN 谓词定义为 = ANY() 量化比较谓词的语法糖。
8.4 <in predicate>
Let RVC be the <row value predicand> and
let IPV be the <in predicate value>.
The expression RVC IN IPV
is equivalent to RVC = ANY IPV
很公平,基于其他答案,例如:什么是“SOME / ANY”和“IN”</a> 或Oracle:'= ANY()' vs. 'IN ()' 我假设我可以使用它们互换。
现在这是我的例子:
select 'match'
where 1 = any( string_to_array('1,2,3', ',')::int[])
-- match
select 'match'
where 1 IN ( string_to_array('1,2,3', ',')::int[])
-- ERROR: operator does not exist: integer = integer[]
-- HINT: No operator matches the given name and argument type(s).
-- You might need to add explicit type casts.
问题是为什么第一个查询有效而第二个返回错误?