Not sure you need to use array why not simple table joins, so a table with your criteria x y z t joined to stuff to give you candidates that do match, then left join with coalesce to add the 'd' select --a.id,b.test_id,coalesce(a.id,b.test_id) as finalresultfrom test aleft join (selecttest_idfrom stuff ainner join (values ('x'),('y'),('z'),('t')) b (v) using(v) group by 1)b on(a.id=b.test_id);
select
--a.id,b.test_id,
coalesce(a.id,b.test_id) as finalresult
from test a
left join (
test_id
from stuff a
inner join (values ('x'),('y'),('z'),('t')) b (v) using(v)
group by 1
)b on(a.id=b.test_id);
pgsql-general by date:
Соглашаюсь с условиями обработки персональных данных