Submitting multiple semi-colon separated Cypher statements through Neo4j Browser

Viewed 21456

I want to submit a list of semi-colon separated Cypher write statements via the web browser but I'm getting errors...

MERGE (a:user{id: 'A'}) 
MERGE (b:product{id: '1'}) 
CREATE UNIQUE (a)-[:USED_BY]->(b); 


MERGE (a:user{id: 'B'}) 
MERGE (b:product{id: '4'})  
CREATE UNIQUE (a)-[:USED_BY]->(b); 

I'm creating new nodes and referring to them in later relationship statements so I want to submit separate queries rather than one long one and I'd like to do this via Cypher.

What's the best way to do this?

7 Answers

There is a simple setting to do this now: Enable multi statement query editor.

Then you can run multiple statements separated by semi-colons ;

neo4j screenshot with the setting highlighted and result of both statements above

I believe apoc.cypher.runMany will do the trick.

CALL apoc.cypher.runMany(statement, {})

(I'm in the process of trying this out via Python Driver. I'll update this post later with my findings.)

MERGE (a:user{id: 'A'}) 
MERGE (b:product{id: '1'}) 
CREATE UNIQUE (a)-[:USED_BY]->(b) 

MERGE (c:user{id: 'B'}) 
MERGE (d:product{id: '4'})  
CREATE UNIQUE (c)-[:USED_BY]->(d)

Try this. It also works

Related