0
votes

in brief: how can we MERGE multiple nodes and relations just like the way we do with MATCH and CREATE: we can do multiple CREATE or MATCH for nodes or relations, separated with comma, but this action is not allowed with MERGE

in detail: suppose I have two graphs:

G1: (a)-[r1]->(b)<-[r2]-(c)
G2: (a)-[r1]->(b)<-[r3]-(d) 

I have G1 inserted in neo4j, and G2 ready to push to db. The normal way to do it is to merge each node pair and then merge the relation; in this example for r1 relation there would be no change in db, since G1 already has the relation, however for the second one, my CQL first create node d then add relation r3

Is there a way to push G2 to db in one step? something like:

MERGE (a), (b), (c), (a)-[r1]->(b)<-[r3]-(d)

to create such result:

(a)-[r1]->(b)<-[r2]-(c)
           ^
           |
          [r3]
           |
          (d)      
1

1 Answers

0
votes

Not with a single MERGE statement. You would need to follow the pattern of doing a MERGE for each node, then a MERGE for each relationship.

That said, Neo4j does use transactions, so while this is broken into multiple clauses in your Cypher query, the transaction is applied atomically when committed.