2

I am attempting to determine if any item from a list of values is present in an array column in PostgreSQL.

SELECT * FROM data WHERE array IN (array)

I have this working using the && operator and a manually constructed array literal:

SELECT id, data FROM things WHERE '{"value", "other"}' && (array_column) 

Is there a better way of accomplishing this?

2
  • Are you really using 9.2 already? (which is not yet released) Commented Jun 20, 2012 at 11:01
  • I am using the current 9.2 dev release, yes Commented Jun 20, 2012 at 23:47

1 Answer 1

3

This is a quite good way, what do you mean by a better way?

There is one thing which could be done some other way, you can create the array using ARRAY[...] like this:

select ARRAY['a', 'b'] && '{"a", "c"}';
Sign up to request clarification or add additional context in comments.

2 Comments

Is there any difference between the two versions?
In my case, I get a typing error when comparing using the ARRAY syntax

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.