apoc.case

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.

Details

Syntax

apoc.case(conditionals [, elseQuery, params ]) :: (value)

Description

For each pair of conditional and read-only queries in the given LIST<ANY>, this procedure will run the first query for which the conditional is evaluated to true. If none of the conditionals are true, the ELSE query will run instead.

Input arguments

Name

Type

Description

conditionals

LIST<ANY>

A list of conditionals, where each conditional is a pair: the first element is a predicate, and the second is a Cypher query to be executed based on that predicate.

elseQuery

STRING

A Cypher query to evaluate if all conditionals evaluate to false. The default is: ''.

params

MAP

A map of parameters to be used in the executed Cypher query. The default is: {}.

Return arguments

Name

Type

Description

value

MAP

The result returned from the evaluated Cypher query.

Usage examples

CALL apoc.case([
  false, 'RETURN "firstFalse" as b',
  false, 'RETURN "secondFalse" as b',
  true, 'RETURN "firstTrue" as b'
]);
Results
value

{b: "firstTrue"}

CALL apoc.case([
  false, 'RETURN "firstFalse" as b',
  false, 'RETURN "secondFalse" as b',
  false, 'RETURN "thirdFalse" as b'
  ],
  'RETURN "elseBranch" as b'
);
Results
value

{b: "elseBranch"}