0

I have a table with a column containing an array (lets call it tags for now).

How can I SELECT from that table all rows where the array column DOES NOT contain a certain tag?

2 Answers 2

2

You can try something like:

SELECT *
FROM your_table
WHERE 'certain tag' != ALL (tags);
Sign up to request clarification or add additional context in comments.

Comments

1

One way to do this would be getting all ids where that tag is contained, then you can exclude those with a subquery:

SELECT *
FROM foo
WHERE id NOT IN (
  SELECT id
  FROM foo
  WHERE tags @> ['specific-tag-here', 'other-tag-here']);

1 Comment

Maybe WHERE not ( tags @> 'specific-tag-here')? Much simpler and faster

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.