select * from (
select * from (
select *, unnest(product_ids) as product_id
from orders
) t1
inner join (
select *, unnest(product_ids) as product_id_1
from orders
) t2 on t1.order_id = t2.order_id
) t3
i want to combine product_id and product_id_1 values into an array and get rid of unnecessary pairs (pair with itself ("A-A"), and each pair occurs twice ("A-B" and "B-A").)