apoc.cypher.runMany

Procedure APOC Core

apoc.cypher.runMany('cypher;\nstatements;', $params, [{statistics:true,timeout:10}]) - runs each semicolon separated statement and returns summary - currently no schema operations

Signature

apoc.cypher.runMany(cypher :: STRING?, params :: MAP?, config = {} :: MAP?) :: (row :: INTEGER?, result :: MAP?)

Input parameters

Name Type Default

cypher

STRING?

null

params

MAP?

null

config

MAP?

{}

Output parameters

Name Type

row

INTEGER?

result

MAP?

Usage Examples

This procedure is useful for executing multiple Cypher statements. We can create a node in one statement and create a relationship to itself in another statement, by running the following query:

CALL apoc.cypher.runMany(
  'CREATE (n:Node {name:$name});
   MATCH (n {name:$name})
   CREATE (n)-[:X {name:$name2}]->(n);',
  {name:"John", name2:"Doe"}
);
Table 1. Results
row result

-1

{constraintsRemoved: 0, indexesRemoved: 0, nodesCreated: 1, rows: 0, propertiesSet: 1, labelsRemoved: 0, relationshipsDeleted: 0, constraintsAdded: 0, nodesDeleted: 0, indexesAdded: 0, labelsAdded: 1, relationshipsCreated: 0, time: 0}

-1

{constraintsRemoved: 0, indexesRemoved: 0, nodesCreated: 0, rows: 0, propertiesSet: 1, labelsRemoved: 0, relationshipsDeleted: 0, constraintsAdded: 0, nodesDeleted: 0, indexesAdded: 0, labelsAdded: 0, relationshipsCreated: 1, time: 0}

If we don’t want to see statistics for each Cypher statement, we can set statistics: false:

CALL apoc.cypher.runMany(
  'CREATE (n:Node {name:$name});
   MATCH (n {name:$name})
   CREATE (n)-[:X {name:$name2}]->(n);',
  {name:"John", name2:"Doe"},
  {statistics: false}
);
Table 2. Results
row result