NULLS in Neo4j
From the documentation NULLs in Neo4j are explained as.
-
nullis used to represent missing/undefined values. -
nullis not equal tonull. Not knowing two values does not imply that they are the same value. So the expressionnull = nullyieldsnulland nottrue. To check if an expression isnull, useIS NULL. -
Arithmetic expressions, comparisons and function calls (except
coalesce) will returnnullif any argument isnull. -
An attempt to access a missing element in a list or a property that doesn’t exist yields
null. -
In
OPTIONAL MATCHclauses,nulls will be used for missing parts of the pattern.
All very neat and dry and abstract.
NULLS are undefined, they have no value that can be determined. In Neo4j, only non-null properties are stored. A different concept to the traditional database way of looking at the world. Each Node, of the same label, can have entirely different properties, and will have null return values where no determinable value for a property has been set.
CREATE (a:person {name:"Bob",age:25});
CREATE (b:person {name:"Gary",weight:100});
MATCH (p:person) RETURN p.name , p.age ,p.weight;
MATCH (p:person) WHERE p.age IS NULL RETURN p.name;
MATCH (p:person) RETURN p.name, COALESCE(p.age,0) as age;
an oddity of NULLS is they don't exist so
MATCH (p:person) WHERE p.age IS NULL RETURN p.name;
is, under the covers, the similar in execution to,
MATCH (p:person) WHERE NOT EXISTS(p.age) RETURN p.name;
Comments
Post a Comment