Skip to content
Advertisement

How to fetch all rows where an array contains any of the fields array elements

I have a table that has a column video_ids, it is of a bigint[] type. I would like to find all the rows that have any of the elements from the array passed in a select statement. So, if I have a row that has a video_ids field that looks like this:

I would like to fetch it if I pass an array that has any of this video_ids. I thought I would do that with any, but I am not sure how to do this in SQL, I have tried with this:

I get an error if I do that:

ERROR: operator does not exist: bigint[] = bigint Hint: No operator matches the given name and argument types. You might need to add explicit type casts.

How can I make such a statement that would do the job for what I need?

Advertisement

Answer

Use the operator && which returns true if the 2 operands have any common items:

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement