Hello,
I am using Neo4j 3.5.4, macOS/Unix version, in the cypher-shell.
I would like to get some help in understanding why these queries create list results that are formatted differently. I ask because I’ve written many queries that return list results in Format 1 with queries written like Code 2. Given the similarity between Code 1 & 2, I don’t understand why one returns one list format and the other another list format.
// ========================= Code 1 ============
</> // INPUT
MATCH (a1:SOURCE)<-[r1:A_IS|B_IS {OUTPUT:"UP"}]-(b:TARGET{ID:"303"})
optional match (b:TARGET)-[r2]->(a2: SOURCE)
// BODY
with a1, a2, r1
// OUTPUT
return a1.NODE_NAME as NODE1, collect(distinct a2.NODE_NAME) as NODE2List ORDER BY NODE1; </>
// ———————— Output Format 1 —————————
+------------------------------------------+
| NODE1 | NODE2List |
+------------------------------------------+
| "AAA" | ["BBB", "CCC", "DDD"] |
+------------------------------------------+
// ========================= Code 2 ============
</> // INPUT
MATCH (a1:SOURCE)<-[r1:A_IS|B_IS {OUTPUT:"UP"}]-(b:TARGET{ID:"79"})
optional match (b:TARGET)-[r2]->(a2: SOURCE)
// BODY
with a1, a2, r1, collect(distinct a2.NODE_NAME) as NODE2List
// OUTPUT
return a1.NODE_NAME as NODE1, NODE2List ORDER BY NODE1; </>
// ———————— Output Format 2 —————————
+-----------------------------+
| NODE1 | NODE2List |
+-----------------------------+
| "AAA" | ["BBB"] |
| "AAA" | ["CCC"] |
| "AAA" | ["DDD"] |
+-----------------------------+