Neo4j Cypher alternative for apoc.coll.union and apoc.coll.unionAll

93 Views Asked by At

In order to substitute

apoc.coll.unionAll(list1, list2) as list3 

looks like I may use + sign in pure Cypher:

WITH [1,2] as list1, [1,2,3,4] as list2 WITH list1 + list2 as list3 

but how to implement apoc.coll.union in plain Cypher which returns a distinct union of the 2 lists?

1

There are 1 best solutions below

0
jose_bacoy On BEST ANSWER

You can unwind the combined list then collect the distinct elements as union list.

WITH [1,2] as list1, [1,2,3,4] as list2 
UNWIND list1 + list2 as l 
RETURN collect(distinct l) as union_list

Result:

╒════════════╕
│"union_list"│
╞════════════╡
│[1,2,3,4]   │
└────────────┘