In Cypher, NULL is used to represent missing or undefined values.
Conceptually, NULL means “a missing unknown value” and it is treated somewhat differently from other values.
E.g. getting a property from a node that does not have said property produces NULL.
Most expressions that take NULL as input will produce NULL.
This includes boolean expressions that are used as predicates in the WHERE clause.
In this case, anything that is not TRUE is interpreted as being false.
NULL is not equal to NULL.
Not knowing two values does not imply that they are the same value.
So the expression NULL = NULL yields NULL and not TRUE.
The logical operators (i.e. AND, OR, XOR, IN) treat NULL as the “unknown” value of three-valued logic.
Here is the truth table for AND, OR and XOR.
| a | b | a AND b | a OR b | a XOR b |
|---|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The IN operator follows similar logic.
If Cypher knows that something exists in a collection, the result will be TRUE.
Any collection that contains a NULL and doesn’t have a matching element will return NULL.
Otherwise, the result will be false.
Here is a table with examples:
| Expression | Result |
|---|---|
2 IN [1, 2, 3] |
|
2 IN [1, |
|
2 IN [1, 2, |
|
2 IN [1] |
|
2 IN [] |
|
|
|
|
|
|
|
Using ALL, ANY, NONE, and SINGLE follows a similar rule.
If the result can be calculated definitely, TRUE or FALSE is returned.
Otherwise NULL is produced.
[][0], head([])
n.missingProperty
NULL: 1 < NULL
NULL: 1 + NULL
NULL: sin(NULL)
Copyright © 2014 Neo Technology