Checking if one value exists in an array is pretty trivial. For example, the following will return true.
SELECT 'hello' = ANY(ARRAY['hello', 'bees'])
But what if I wanted to check if any of multiple values exist in an array? For example, I want to return true if 'hello' OR 'bye' exists in an array. I want to do something like
SELECT ['hello', 'bye'] = ANY(ARRAY['hello', 'bees'])
but that doesn't seem to work.
Edit:
I'm also looking to figure out how I can check if any of multiple values exist in an array where the multiple values have common prefixes.
For example, if I want to return true if the array contains any element with the prefix of 'hello'. So I basically want something like
SELECT ARRAY['hello%'] && ARRAY['helloOTHERSTUFF']
to be true.
ARRAY['hello', 'bye'] && ARRAY['hello', 'bees']ARRAY['hello'] && ARRAY['helloOTHERSTUFF']to be true. I'll also edit the original post.field_name ILIKE 'hello%'except for arrays. Is that not possible?anybutlikeinstead of=), but not vise versa. The general pattern for complex comparison of two (or more) arrays isexists 1 from unnest(<array1>) as t1(x1) join unnest(<array2>) as t2(x2) on (<join condition>), where<join condition>for your example could bex1 ilike x2.