apoc.when

Procedure

apoc.when(condition BOOLEAN, ifQuery STRING, elseQuery STRING, params MAP<STRING, ANY>) - this procedure will run the read-only ifQuery if the conditional has evaluated to true, otherwise the elseQuery will run.

This procedure is not considered safe to run from multiple threads. It is therefore not supported by the parallel runtime (introduced in Neo4j 5.13). For more information, see the Cypher Manual → Parallel runtime.

Signature

apoc.when(condition :: BOOLEAN, ifQuery :: STRING, elseQuery =  :: STRING, params = {} :: MAP) :: (value :: MAP)

Input parameters

Name Type Default

condition

BOOLEAN

null

ifQuery

STRING

null

elseQuery

STRING

params

MAP

{}

Output parameters

Name Type

value

MAP

Usage examples

CALL apoc.when(false, 'RETURN 7 as b');
Table 1. Results
value

{}

CALL apoc.when(true, 'RETURN $a + 7 as b', 'RETURN $a as b',{a:3})
Table 2. Results
value

{b: 10}