21

I want to execute several queries at the same time on the browser console, here are my requests :

CREATE (newNode1:NEW_NODE)
CREATE (newNode2:NEW_NODE)
MATCH (n1:LABEL_1 {id: "node1"}) CREATE (newNode1)-[:LINKED_TO]->(n1)
MATCH (n2:LABEL_2 {id: "node2"}) CREATE (newNode2)-[:LINKED_TO]->(n2)

When I execute them one by one there is no problem, but when I execute them at the same time, I get the following error : WITH is required between CREATE and MATCH

Is there any way to correct this?

jimmy
  • 385
  • 1
  • 3
  • 10

1 Answers1

22

Add a couple of WITHs?

CREATE (newNode1:NEW_NODE)
CREATE (newNode2:NEW_NODE)
WITH newNode1, newNode2
MATCH (n1:LABEL_1 {id: "node1"}) 
CREATE (newNode1)-[:LINKED_TO]->(n1)
WITH newNode1, newNode2
MATCH (n2:LABEL_2 {id: "node2"}) 
CREATE (newNode2)-[:LINKED_TO]->(n2)

Alternatively, you could do it in a different order and avoid the WITHs, the difference being that it won't create anything if n1/n2 don't MATCH.

MATCH (n1:LABEL_1 { id: "node1" }) 
MATCH (n2:LABEL_2 { id: "node2" }) 
CREATE (newNode1:NEW_NODE)-[:LINKED_TO]->(n1) 
CREATE (newNode2:NEW_NODE)-[:LINKED_TO]->(n2)
Eve Freeman
  • 32,467
  • 4
  • 86
  • 101
  • Finally, I used the samed method as you pointed. I wrote all my matches before my creates. I thought there was something to separate two queries but didn't find. Thank you! – jimmy Jan 28 '14 at 05:59