0

I have a table like this

| id            | data                |
|---------------|---------------------|
| org:abc:basic | {org,org:abc:basic} |
| org:xyz:basic | {org,basic}         |
| org:efg:basic | {org}               |

I need to write a query to select all the rows which doesn't have the id inside the data column.

Or at least I need to query all the records which doesn't have a text starting from org: and ending with :basic within data. Currently for this I try to run

SELECT * FROM t_permission WHERE 'org:%:basic' NOT LIKE ANY (data)

query which returns everything even the first row.

1 Answer 1

1

you can use the <> operator with ALL against the array:

select *
from the_table
where id <> all(data);
Sign up to request clarification or add additional context in comments.

2 Comments

This works. This and this select * from the_table where not id = any(data); and select * from the_table where id != all(data); are the same ? Because this also returns the same.
<> is the "not equals" operator in standard SQL. Postgres also accepts the non-standard != operator which does exactly the same.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.