neo4j community server 4.3.3 on Ubuntu 20.04
Dear all, there is a strange behavior in the OPTIONAL MATCH
.
Maybe, I misunderstood, but would be nice if someone could explain me.
I have this simple query:
MATCH (x:X {uuid: 'ccc9c72a-3a1d-4683-8cf9-c98fba83750c'})
RETURN x
which return exactly one object:
╒══════════════════════════════════════════════════════════╕
│"x" │
╞══════════════════════════════════════════════════════════╡
│{"uuid":"ccc9c72a-3a1d-4683-8cf9-c98fba83750c"} │
└──────────────────────────────────────────────────────────┘
Now, I change the query, without modifying the first part, adding an OPTIONAL
relationship:
OPTIONAL MATCH (x:X {uuid: 'ccc9c72a-3a1d-4683-8cf9-c98fba83750c'})-[:REL]->(y:Y)
RETURN x,y
I expected the query to return exactly the same node as before, with all the y
related.
If there are instances of Y
into the DB, the query succeed.
But, if there is no 'Y' instance into the DB, the query returns nothing as in the following sample:
╒════╤═══════╕
│"x" | "y" │
╞════╪═══════╡
│null| null │
└────┴───────┘
I expected something like
╒════════════════════════════════════════════════════════╕
│"x" │"y" │
╞════════════════════════════════════════════════╪═══════╡
│{"uuid":"ccc9c72a-3a1d-4683-8cf9-c98fba83750c"} │null │
└────────────────────────────────────────────────┴───────┘
Where is the error?
Thank you