skip to Main Content

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?

2

Answers


  1. Use the ANY operator:

    SELECT * 
    FROM table 
    WHERE something = ANY ('{"val1","val2"}'::text[]);
    
    Login or Signup to reply.
  2. You are looking for ANY:

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

    But if you insist on using IN, you can achieve the same with UNNEST:

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

    (online demo)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search