I have two test queries
CREATE (a:TEST)
DELETE a
WITH a
WHERE a <> NULL
RETURN (a:TEST)
Which returns
Added 1 label, created 1 node, deleted 1 node, statement completed in 0 ms.
And
CREATE (a:TEST)
DELETE a
WITH a
WHERE a IS NOT NULL
RETURN (a:TEST)
Which returns
Node with id 1738 has been deleted in this transaction
According to the documentation, "<>" is the inequality operator. So my understanding is that "a <> NULL" and "a IS NOT NULL" are equivalent in Cypher. At the very least, I would expect "a IS NOT NULL" to be the more reliable filter (as it is its own dedicated compare operator). This seems like it might be an edge case bug of creating and deleting a node in the same transaction, but the documentation on IS NOT NULL doesn't say anything beyond (implied) "it is an operator", so this could be intentional if there is a subtle deference.
So why does a <> NULL work when a IS NOT NULL doesn't? AKA, What is the deference between these two comparisons?
I am using Cypher version 3.1, and Neo4j version 3.1.1
In Cypher, NULL is used to represent missing or undefined values. Thus equality tests involving NULL will always be undefined also - which is treated as false. See https://neo4j.com/docs/developer-manual/current/cypher/syntax/working-with-null/ for details.
In your example, the identifier a continues to refer to a node, even after the DELETE a. It is not NULL. In the first example, you are comparing a non-NULL identifier to NULL, which is always unknown and thus false. Hence the RETURN a never gets evaluated and you only see output about the creation and deletion.
In the second example, the check is a IS NOT NULL, which is true. a refers to a node that has been deleted from the graph. So the clause RETURN a is evaluated.
You receive the error Node with id 1738 has been deleted in this transaction because the rendering of the node tries to read the node from the graph, where it has been deleted. It is debatable that, rather than an error, the node representation should still be returned. The argument that the identifier a continues to reference the node has merit. However, at this time, Neo4j doesn't provide the kind of isolation required to achieve this and I do not believe the OpenCypher group has a position on whether it should or should not work that way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With