I have the following table:
╔════╦════════════════════════════════════════╗
║ id ║ value ║
╠════╬════════════════════════════════════════╣
║ 1 ║ ['friend', 'apple', 'cat'] ║
║ 2 ║ ['cat', 'friend', 'dog'] ║
║ 3 ║ ['pasta', 'best-friend', 'lizard'] ║
║ 4 ║ ['wildcat', 'potato', 'alices-friend'] ║
╚════╩════════════════════════════════════════╝
My goal is to return all rows where value
contains a given array. For example:
['friend', 'cat']
should return rows1
and2
.['%friend%', '%cat%']
should return rows1
,2
and4
.
Currently I'm using this command:
SELECT DISTINCT id, value
FROM table
WHERE value @> (ARRAY['friend', 'cat']::VARCHAR[]);
But it's not working for example 2 listed above, when (array['%friend%', '%cat%']::varchar[])
.
As it works for example 1, I think the problem is with the %
symbols, but I don't know how to handle this, since I don't need to explicitly match the values.