Let's say I have a simple table such as this one:
id_ | tags
---------------
0 | foo1, baz
1 | bar1, qux
The id_ column is of type SERIAL and the tags column is of type TEXT[] (text array).
In order to search the tags column with the LIKE operator I use a combination of unnest and DISTINCT ON like this:
SELECT DISTINCT ON (id_) *
FROM (
SELECT unnest(tags) tag, *
FROM Records
) x
WHERE
(tag LIKE '%o%');
This works fine. The query returns row 0 like it should.
Now I'm trying to figure out a way to invert the query, so that it only returns rows that don't match the LIKE expression. I tried with this:
WHERE
(tag NOT LIKE '%o%');
but it doesn't seem to work... My idea was that this query should return row 1 only, but it returns both rows.
I also tried with sub queries, for example like this one:
WHERE
(x.id_ NOT IN (SELECT id_ FROM Records WHERE tag like '%o%'));
But it still returns both rows.
Does anyone know how this can be fixed?