apoc.case

Procedure APOC Core

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

Signature

apoc.case(conditionals :: LIST? OF ANY?, elseQuery =  :: STRING?, params = {} :: MAP?) :: (value :: MAP?)

Input parameters

Name Type Default

conditionals

LIST? OF ANY?

null

elseQuery

STRING?

params

MAP?

{}

Output parameters

Name Type

value

MAP?

Usage Examples

CALL apoc.case([
  false, 'RETURN "firstFalse" as b',
  false, 'RETURN "secondFalse" as b',
  true, 'RETURN "firstTrue" as b'
]);
Table 1. 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'
);
Table 2. Results
value

{b: "elseBranch"}