0

I'm trying to build a query that returns records that have a character varying[] column that does not contain multiple values? Something like:

WHERE {char1,char2,char3} != ALL(char_array_col)

Any help appreciated, thank you.

1 Answer 1

1

If you have your multiple values in an array, you can do:

where not myarray  @> array['val1', 'val2', 'val3']

This ensures that myarray does not contain all of the values.

On the other hand, if you want to ensure that myarray does not contain any of the values, use overlap operator &&:

where not myarray  && array['val1', 'val2', 'val3']
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks - unfortunately I get syntax errors when trying either of those. The latter one is the one I need. "No operator matches the given name and argument types. You might need to add explicit type casts."
@tom_nb_ny: so just cast: where not myarray && array['val1', 'val2', 'val3']::character varying[]
@tom_nb_ny: please share the entire error message.
I fiddled around and got it to execute - pet IS NULL OR NOT pet && '{cat,dog}' worked. Thanks for your help.
@tom_nb_ny: mm ok, so that's implicit conversion of the string on the left side of the operator to an array. Fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.