I have 2 arrays that contains non-unique values. For example: ["A", "B", "B", "C"] and ["A", "A", "A", "B", "C", "D"].
If I use the ARRAY_SYMDIFF function I only get ["D"] but what I’m searching for is something that will take the number of occurence of a single value into account and will give me this result: ["A", "A", "B", "D"].
There is no simple function. Doing in application is easy.
The following is SQL gives expected results.
SELECT ARRAY_FLATTEN((SELECT RAW ARRAY t FOR t1 IN ARRAY_RANGE(0,ABS(ARRAY_LENGTH(a1)-ARRAY_LENGTH(a2))) END
FROM ARRAY_UNION(a,b) AS t
LET a1 = ARRAY v FOR v IN a WHEN t = v END, a2 = ARRAY v FOR v IN b WHEN t = v END
LET a = ["A", "B", "B", "C"], b= ["A", "A", "A", "B", "C", "D"];
Thank you. This is working fine on CB 5.x. But because ARRAY_UNION is not available on v4.5 on which I need to ensure compatibility, do you know any equivalent of this function?
I know I could do it in application in an easy way but I don’t really have a hand on what the client will do so it’s better for me if I manage to directly get the wanted result. And this “diff” is only a part of a bigger query.
By replacing those statements I got an empty array instead of the expected result. I presume this is because t is now referring to an item of the union instead of the full array? But I didn’t managed to get it working…