Can't figure out how to make combinations of arrays without repetitions.
INPUT is an array of n variables LIKE '{A,B,C,D,E}'
Variable A is always single array LIKE '{"A"}' or '{"D,C"}' or '{"D,A,B"}' etc..
What I need is to combine INPUT with A(i)
EXAMPLE:
1. A = '{"B"}' --> att='{"B,A","B,C","B,D","B,E"}'
2. A = '{"B,C"}' --> att='{"B,C,A","B,C,D","B,C,E"}'
3. A = '{"B,C,A"}' --> att='{"B,C,A,D","B,C,A,E"}'
4. A = '{"B,C,A,D"}' --> att='{"B,C,A,D,E"}'
As far I have this:
WITH A(i) AS (SELECT * FROM unnest(ARRAY['A,B'])),
B(j) AS (SELECT * FROM unnest(ARRAY['A','B','C','D'])),
cte AS ( SELECT A.i ||','|| B.j
FROM A
CROSS JOIN B
)
SELECT ARRAY ( SELECT * FROM cte) INTO att;
But it makes duplicity:
"{"A,B,A","A,B,B","A,B,C","A,B,D"}"
ARRAY[...]constructorunnest()function. To avoid multiple self-joins, and multiplea.x <> b.yclauses, you could use a recursive CTE (usingcandidate_element <> ALL( cte_array_expression_here)And restrict the maximum number of elements by limiting the recursion depth.