NULLS in Neo4j

From the documentation NULLs in Neo4j are explained as.

  • null is used to represent missing/undefined values.

  • 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. To check if an expression is null, use IS NULL.

  • Arithmetic expressions, comparisons and function calls (except coalesce) will return null if any argument is null.

  • An attempt to access a missing element in a list or a property that doesn’t exist yields null.

  • In OPTIONAL MATCH clauses, 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

Popular posts from this blog

Property DataType - apoc.meta.type

Stopping and Starting the Neo4j Database