Case Expression
The CASE
expression is used to define conditional logic, similar to how if
statements work in
programming languages. There are two variants of conditional expressions in Cypher:
- Simple form which compares an expression against multiple expressions
- General form with multiple conditional statements.
Simple form
In the simple form, input is compared against each WHEN
in order until a match is found. If no
match is found, the expression in the ELSE
is returned. If there is no ELSE
, NULL
is returned.
Syntax
Example:
Output:
General form
In the general form, conditional statements are evaluated in order until a true
statement is
found. If no match is found, the expression in the ELSE
is returned. If there is no ELSE
, NULL
is returned.
Syntax
Example:
Output: