我试图让这个查询工作
select *
from DUALS
where num in ('1,2,3')
字符串 '1,2,3' 即时创建,因此我无法将其替换为代码中的整数列表。
所以我以这个结束:
select *
from DUALS
where num in (select unnest (string_to_array('1,2', ',')::integer[]))
它有效,但我想知道它是否可以简化。不能使用“Any”运算符。
最佳答案
你可以只使用这个代码:
select *
from DUALS
where num = any('{1,2,3}'::int[])
关于PostgreSQL:如何将逗号分隔的字符串转换为使用 IN 运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44003762/