apoc.cypher.runWrite

Details

Syntax

apoc.cypher.runWrite(statement, params) :: (value)

Description

Alias for apoc.cypher.doIt.

Input arguments

Name

Type

Description

statement

STRING

The Cypher statement to run.

params

MAP

The parameters for the given Cypher statement.

Return arguments

Name

Type

Description

value

MAP

The result returned from the Cypher statement.

This procedure cannot perform SCHEMA operations. To run a query in SCHEMA mode, use apoc.cypher.runSchema.

Using dynamic labels in Cypher

Node labels and relationship types can be referenced dynamically in Cypher without using APOC.

Cypher syntax for creating, matching and merging labels and types dynamically
CREATE (n1:$(label))-[r:$(type)]->(n2:$(label))
MERGE (n1:$(label))-[r:$(type)]->(n2:$(label))
MATCH (n1:$(label))-[r:$(type)]->(n2:$(label))

The dynamically calculated type must evaluate to a STRING or LIST<STRING>. For more information, see the Cypher Manual → CREATE, MERGE, MATCH.

Example

Given this dataset:

CREATE (:Person {name: 'Alice', age: 30}),
     (:Person {name: 'Bob', age: 25})

The following query dynamically constructs and executes a write statement, using parameters to pass values into the inner statement:

CALL apoc.cypher.runWrite(
  'MATCH (p:Person {name: $name})
  SET p.age = $newAge
  RETURN p.name AS name, p.age AS age',
  {name: 'Alice', newAge: 31}
)
YIELD value
RETURN value.name AS name, value.age AS age
Results
name age

"Alice"

31

Each row returned by the inner statement is yielded as a value map, with the result columns as map keys. apoc.cypher.runWrite is an alias for apoc.cypher.doIt.