13.1.4.1. Conditional Cypher Execution

CALL apoc.when(condition, ifQuery, elseQuery:'', params:{}) yield value

based on the conditional, executes read-only ifQuery or elseQuery with the given parameters

CALL apoc.do.when(condition, ifQuery, elseQuery:'', params:{}) yield value

based on the conditional, executes writing ifQuery or elseQuery with the given parameters

CALL apoc.case([condition, query, condition, query, …​], elseQuery:'', params:{}) yield value

given a list of conditional / read-only query pairs, executes the query associated with the first conditional evaluating to true (or the else query if none are true) with the given parameters

CALL apoc.do.case([condition, query, condition, query, …​], elseQuery:'', params:{}) yield value

given a list of conditional / writing query pairs, executes the query associated with the first conditional evaluating to true (or the else query if none are true) with the given parameters

Sometimes queries require conditional execution logic that can’t be adequately expressed in Cypher, even with CASE.

APOC’s conditional execution procedures simulate an if / else structure, where a supplied boolean condition determines which cypher query is executed.