apoc.when

This procedure is deprecated. Use Cypher’s conditional queries instead.

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

Details

Syntax

apoc.when(condition, ifQuery [, elseQuery, params ]) :: (value)

Description

This procedure will run the read-only ifQuery if the conditional has evaluated to true, otherwise the elseQuery will run.

Input arguments

Name

Type

Description

condition

BOOLEAN

The predicate deciding if to run the `ifQuery`or not.

ifQuery

STRING

The Cypher statement to run if the condition is true.

elseQuery

STRING

The Cypher statement to run if the condition is false. The default is: ``.

params

MAP

The parameters for the given Cypher statement. The default is: {}.

Return arguments

Name

Type

Description

value

MAP

The result returned from the evaluated Cypher query.

Usage examples

apoc.when
CALL apoc.when(false, 'RETURN 7 as b');
Cypher’s conditional queries
WHEN false THEN RETURN {b: 7} AS value
ELSE RETURN {} AS value
Results
value

{}

apoc.when
CALL apoc.when(true, 'RETURN $a + 7 as b', 'RETURN $a as b',{a:3})
Cypher’s conditional queries
WITH 3 AS a
CALL (a) {
    WHEN true THEN RETURN a + 7 AS b
    ELSE RETURN a AS b
}
RETURN { b: b} AS value
Results
value

{b: 10}