Unexpected collection behavior in Cypher

Using http://console.neo4j.org as a sandbox, I came across the following unexpected behavior:

Statement 1 - returns 1 row with a collection containing Neo Node

MATCH (n:Crew) 
WHERE n.name="Neo" 
WITH COLLECT(n) AS c1
WITH c1+[] AS c2
RETURN c2

Operator 2 - returns 0 rows (unexpectedly)

MATCH (n:Crew) 
WHERE n.name="Neo" 
WITH COLLECT(n) AS c1
MATCH (n:Crew) 
WHERE n.name="NoOne"
WITH c1+COLLECT(n) AS c2
RETURN c2

Statement 3 - Returns 1 row containing an empty collection

MATCH (n:Crew) 
WHERE n.name="NoOne"
WITH COLLECT(n) AS c1
RETURN c1

I do not understand why Statement 2 does not return the same result as Statement 1 , because it must return a collection containing Neo node, as in Statement 1 .
Statement 3 shows that the second MATCHin Statement 2 should result in an empty collection.

Cypher? , , .

+4
2

, . MATCH Query 2: ( c1) MATCH, MATCH, MATCH ( ) . OPTIONAL MATCH, , .

UPDATE: . , tl, dr - , COLLECT(n) Statement 2 , Statement 3; WITH c1+COLLECT(n) AS c2 , MATCH c1.

+5

, , , , , MATCH :

OPTIONAL MATCH (n:Crew) 
WHERE n.name="Neo" 
WITH COLLECT(n) AS c1
OPTIONAL MATCH (n:Crew) 
WHERE n.name="NoOne"
WITH c1+COLLECT(n) AS c2
RETURN c2
+1

Source: https://habr.com/ru/post/1656804/


All Articles