The NULLIF
expression is a conditional expression that compares two values and returns null
if they are equal; otherwise, it returns the first value. It is often used to handle cases where specific values should be treated as null
, which can be helpful for conditional data cleansing or handling default values.
<nullif expression> ::=
"NULLIF" "(" <value expression> "," <value expression> ")"
The NULLIF(V1, V2)
expression is equivalent to the following CASE
expression:
CASE
WHEN V1 = V2 THEN NULL
ELSE V1
END
Example Graph
The following examples run against this graph:

To create this graph, run the following query against an empty graph:
INSERT (p1:Paper {_id:'P1', title:'Efficient Graph Search', score:6, author:'Alex', publisher:'PulsePress'}),
(p2:Paper {_id:'P2', title:'Optimizing Queries', score:9, author:'Alex'}),
(p3:Paper {_id:'P3', title:'Path Patterns', score:7, author:'Zack', publisher:'BrightLeaf'}),
(p1)-[:Cites {weight:2}]->(p2),
(p2)-[:Cites {weight:1}]->(p3)
Example
MATCH (n:Paper)
RETURN n.title, NULLIF(n.author, "Alex")
Result:
n.title | NULLIF(n.author, "Alex") |
---|---|
Efficient Graph Search | null |
Optimizing Queries | null |
Path Patterns | Zack |