So I know that with a postgresql array I can do a query like:
SELECT *
FROM deck
WHERE card_ids_array @> ARRAY[
'd438faa9-7920-437a-8d1c-682fade5d350',
'b361d7e2-6873-4890-8f87-702d9c89c5ad'
];
to get all the decks with those values in the array. But my array might have multiple copies of the same card id. How can I do a query like:
SELECT *
FROM deck
WHERE card_ids_array @> ARRAY[
'd438faa9-7920-437a-8d1c-682fade5d350',
'b361d7e2-6873-4890-8f87-702d9c89c5ad',
'b361d7e2-6873-4890-8f87-702d9c89c5ad'
];
and get only decks with two instances of 'b361d7e2-6873-4890-8f87-702d9c89c5ad' in their card_ids_array? When I do that query, I get all decks with at least one of the card ids, not the ones with at least one of the first id and at least two of the second.
My only idea so far is to change my array to contain the quantity of cards in it as well, and add another entry for each quantity. Like 'b361d7e2-6873-4890-8f87-702d9c89c5ad-1', 'b361d7e2-6873-4890-8f87-702d9c89c5ad-2', and then I could do a query for 1 through 6 if the query is for just one instance, or just 6 if they only want decks with 6 or more instances of the card.