Reputation: 2255
Considering an array of numeric strings, e.g. arr = ['202', '303', '1', ...] and the following table:
MyTable
code VARCHAR(255)
Is possible to find in a single query:
There's some way to achieve that?
I'm using PostgreSQL.
Upvotes: 1
Views: 269
Reputation: 1269883
You can unnest the array and use join
s or something similar
For the first condition:
select el
from unnest(ar) el
where not exists (select 1 from t where t.code = el);
Similar logic can be used for the second, but you might want select distinct
:
select t.code
from t
where not exists (select 1 from unnest(ar) el where t.code = el);
If you want both in a single query, you can use union all
or full join
:
select el, t.code
from unnest(ar) el full join
t
on t.code = el
where t.code is null or el is null;
Upvotes: 2