我有以下查询:检查数组中是否有任何子串出现在字符串中?
select case when count(*)>0 then true else false end
from tab
where param in ('a','b') and position('T' in listofitem)>0
此检查是否存在在列listofitem
'T'
如果确实如此的计数> 0。基本上,它是子串的搜索。
这在这个私人案件中效果很好。不过,我的真实情况是,我有text[]
调用sub_array
意味着多个值来检查。如何修改查询以处理sub_array
类型?我更喜欢在查询中使用它,而不是使用LOOP的函数。
我actualy需要的是:
select case when count(*)>0 then true else false end
from tab
where param in ('a','b') and position(sub_array in listofitem)>0
这因为sub_array
不工作的类型是Text[]
试试' unnest'阵列 –