apoc.do.when
This procedure is deprecated. Use Cypher’s conditional queries instead. |
Syntax |
|
||
Description |
Runs the given read/write |
||
Input arguments |
Name |
Type |
Description |
|
|
The predicate that determines whether to execute the |
|
|
|
The Cypher statement to run if the condition is true. |
|
|
|
The Cypher statement to run if the condition is false. |
|
|
|
The parameters for the given Cypher statement. The default is: |
|
Return arguments |
Name |
Type |
Description |
|
|
The result returned from the evaluated Cypher query. |
Usage Examples
The following will create a node with a name
property of A
, as per the ifQuery, because the predicate is true:
CALL apoc.do.when(true,
'CREATE (a:Node { name:"A" }) RETURN a AS node',
'CREATE (b:Node { name:"B" }) RETURN b AS node',
{}
)
YIELD value
RETURN value.node AS node;
WHEN true THEN CREATE (a:Node { name:"A" }) RETURN a AS node
ELSE CREATE (b:Node { name:"B" }) RETURN b AS node
node |
---|
(:Node {name: "A"}) |
The following will create a node with a name
property of B
, as per the elseQuery, because the predicate is false:
CALL apoc.do.when(false,
'CREATE (a:Node { name:"A" }) RETURN a AS node',
'CREATE (b:Node { name:"B" }) RETURN b AS node',
{}
)
YIELD value
RETURN value.node AS node;
WHEN false THEN CREATE (a:Node { name:"A" }) RETURN a AS node
ELSE CREATE (b:Node { name:"B" }) RETURN b AS node
node |
---|
(:Node {name: "B"}) |