apoc.do.case
Procedure
apoc.do.case(conditionals [Any], elseQuery String, params Map<String, Any>)
- for each pair of conditional queries in the given list, 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.
Signature
apoc.do.case(conditionals :: LIST? OF ANY?, elseQuery = :: STRING?, params = {} :: MAP?) :: (value :: MAP?)
Usage Examples
The following will create a node with a name
property of B
, because that’s the first of the conditionals to evaluate to true:
CALL apoc.do.case([
false,
'CREATE (a:Node{name:"A"}) RETURN a AS node',
true,
'CREATE (b:Node{name:"B"}) RETURN b AS node'
],
'CREATE (c:Node{name:"C"}) RETURN c AS node',{})
YIELD value
RETURN value.node AS node;
node |
---|
(:Node {name: "B"}) |
The following will create a node with a name
property of C
, as per the elseQuery, because all conditionals evaluate to false:
CALL apoc.do.case([
false,
'CREATE (a:Node{name:"A"}) RETURN a AS node',
false,
'CREATE (b:Node{name:"B"}) RETURN b AS node'
],
'CREATE (c:Node{name:"C"}) RETURN c AS node',{})
YIELD value
RETURN value.node AS node;
node |
---|
(:Node {name: "C"}) |
Was this page helpful?