0

Say I have table in Postgres with column data of type JSONB. This column contains pretty complex object for example:

{
  ...,
  gender: ['men', 'women'],
  ...
}

I have query like gender=men&gender=women&gender=something_else and want to find all rows in table where ANY of gender's members `IN ('men', 'women', 'something_else'). For example:

SELECT uuid, data ->> 'gender' FROM "OX_Articles" WHERE data ->> 'gender' INTERSECTS WITH (men', 'women', 'something_else');

Of course we haven't keywords INTERSECTS WITH.

1

1 Answer 1

1

Either in (...) or = any(array[...]) should work.

They should have similar performances. I favor =any because it handles empty RHS (whereas IN can't handle empty literal tuples) and I'd expect whatever postgres bindings I have to convert the host language's arrays/lists/arraylists to pg arrays, not pg tuples.

Sign up to request clarification or add additional context in comments.

Comments

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.