Вы можете удалить массив и использовать join
s или что-то подобное
Для первого условия:
select el
from unnest(ar) el
where not exists (select 1 from t where t.code = el);
Аналогичные логики c можно использовать для второго, но вы можете захотеть select distinct
:
select t.code
from t
where not exists (select 1 from unnest(ar) el where t.code = el);
Если вы хотите оба в одном запросе, вы можете использовать union all
или 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;