I'm having a post, each post has tags (varchar[]), and I'm trying to find related ones according to tags. This is why I want to check if all tags of the target post or any of its subsets are contained in the 'tags' arrays of other posts.
I've checked several sources:
Postgres: check if array field contains value?
https://www.postgresql.org/docs/9.1/functions-array.html
According to them, @> should be suitable for this case, however neither
select * from posts where tags @> '{"California", "K-8"}';
nor
select * from posts where tags @> array['California', 'K-8']::varchar[];
work properly: I got an empty result while I have two posts with tags:
{'California','K-8','Legislation','AB77'}, {'California','K-8','Tips & Tricks'}
I would greatly appreciate it if someone could advise a solution to this issue :-)
EDIT: I've figured out what was wrong - the issue was in the format of stored data: after I had changed
{'California','K-8','Tips & Tricks'}
to
{California,K-8,"Tips & Tricks"}
in pgAdmin everything started to work properly.