Skip to main content
added 239 characters in body
Source Link
avi
  • 1.9k
  • 6
  • 31
  • 48

I have the following query:

select case when count(*)>0 then true else false end
from tab
where param in ('a','b') and position('T' in listofitem)>0

This checks if 'T' exists in the column listofitem and if it does the count is > 0. Basically it's a search for sub string.

This works well in this private case. However my real case is that I have text[] called sub_array meaning multiple values to check. How can I modify the query to handle the sub_array type? I prefer to have it in a query rather than a function with a LOOP.

What I actualy need is:

select case when count(*)>0 then true else false end
from tab
where param in ('a','b') and position(sub_array in listofitem)>0

This is not working since sub_array is of type Text[]

I have the following query:

select case when count(*)>0 then true else false end
from tab
where param in ('a','b') and position('T' in listofitem)>0

This checks if 'T' exists in the column listofitem and if it does the count is > 0. Basically it's a search for sub string.

This works well in this private case. However my real case is that I have text[] called sub_array meaning multiple values to check. How can I modify the query to handle the sub_array type? I prefer to have it in a query rather than a function with a LOOP.

I have the following query:

select case when count(*)>0 then true else false end
from tab
where param in ('a','b') and position('T' in listofitem)>0

This checks if 'T' exists in the column listofitem and if it does the count is > 0. Basically it's a search for sub string.

This works well in this private case. However my real case is that I have text[] called sub_array meaning multiple values to check. How can I modify the query to handle the sub_array type? I prefer to have it in a query rather than a function with a LOOP.

What I actualy need is:

select case when count(*)>0 then true else false end
from tab
where param in ('a','b') and position(sub_array in listofitem)>0

This is not working since sub_array is of type Text[]

Source Link
avi
  • 1.9k
  • 6
  • 31
  • 48

Check if any substring from array appear in string?

I have the following query:

select case when count(*)>0 then true else false end
from tab
where param in ('a','b') and position('T' in listofitem)>0

This checks if 'T' exists in the column listofitem and if it does the count is > 0. Basically it's a search for sub string.

This works well in this private case. However my real case is that I have text[] called sub_array meaning multiple values to check. How can I modify the query to handle the sub_array type? I prefer to have it in a query rather than a function with a LOOP.