Is it possible to adjust an array in PostgreSQL to fit with an IN operator?

Something like:

SELECT * FROM table WHERE something IN ('{"val1","val2"}'::text[]);

I tried it with array_to_string().

SELECT * FROM table WHERE something IN (array_to_string('{"val1","val2"}'::text[]));

But I guess that makes it to this:

SELECT * FROM table WHERE something IN ('val1,val2'); --one single string

I guess the single values must also be surrounded with apostrophes.

Is that possible somehow, or can it be solved in a completely different way?

>Solution :

Use the ANY operator:

SELECT * 
FROM table 
WHERE something = ANY ('{"val1","val2"}'::text[]);

Leave a Reply