I am trying to write an postgresql query and one of the where statements is a check to see if an array of filters that a user passes contains a value the array of types on a database column has in a json blob.
for example, if the user sets their filters to look for values
["prettyfly","likespizza"]
and the table has
["eatingfood","prettyfly"]
in a column it would return that row. Here is what I’ve tried, but it isn’t quite right
filterQuery = `AND ['${coreValueFilters.join("','")}'] = ANY(hashtags)`
hashtags being the name of the table.
Here is a clearer example without variables
filterQuery = `AND ["prettyfly","likespizza"] = ANY(hashtags)`
>Solution :
Use &&
anyarray && anyarray → boolean
Do the arrays overlap, that is, have any elements in common?
ARRAY[1,4,3] && ARRAY[2,1] → t
From https://www.postgresql.org/docs/current/functions-array.html