I need to search a large table (over 100million records) using quite a complex set of rules.
At present I have a table that looks like this
CREATE TABLE equipment (
id serial primary key,
description varchar,
code integer,
tags varchar[]
)
And I need to query based on
1) A specific list of codes (WHERE code IN (1,4,5,8)
2) An array of tags that are NOT in the tags array
3) An array of tags that are IN the tags array but at least two need to be present
SELECT * FROM equipment WHERE
code IN (1,3,6,7,8)
AND NOT ('{sports, outdoors, camping}' && tags)
AND ('{tennis, squash, badminton, volleyball}' && tags)
But I do not know how to make that at least two of the values (tennis, squash, badminton, volleyball) overlap the tags array.
I am using Postgres 10.6