cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Multiple Match-Where-Merge in one Request

Hello,
I have created an excel-sheet that uses the excel-functions to write the necessary code to implement the relations of the excel-sheet to Neo4J with Cypher code. To do that I write the code in an extra row and copy-paste it into Neo4J. This works perfectly with the nodes.
Example:

Create (a2: Organisation { Dach_Organisation: 'xxxxxx', ORGA_ID: '926785240' })
Create (a3: Organisation { Dach_Organisation: 'xxxxxx', ORGA_ID: '1453453434' })

I can copy all the creation requests in Neo4J at once and it works.

My problem starts with the code to create the relations.

MATCH (a: Organisation), (b:Projekt) 
WHERE a.ORGA_ID= '926785240' AND b.PROJEKT_ID= '207481'
MERGE (a) - [r: Arbeit { Foerdersumme_in_EUR:' ' ,TIE_BY_ATTRIBUTE_1: '' ,TIE_BY_ATTRIBUTE_2: '' } ] -> (b)

MATCH (a: Organisation), (b:Projekt) 
WHERE a.ORGA_ID= '' AND b.PROJEKT_ID= '03F0622A_BMBF'
MERGE (a) - [r: Arbeit { Foerdersumme_in_EUR:' xxxx' ,TIE_BY_ATTRIBUTE_1: '' ,TIE_BY_ATTRIBUTE_2: '' } ] -> (b)

If I just use it one time it works but if I try two or more of this at the same time I get the following error:

WITH is required between MERGE and MATCH (line 4, column 1 (offset: 202))
"MATCH (a: Organisation), (b:Projekt)"
 ^

Is there a way to prevent that error? I would like to copy and past a lot of this requests and do them at once.

Thank You!

2 REPLIES 2

clem
Graph Steward

I think you need semi-colons between the merge statements. I think the problem is that since you've inadvertently made it one big block, Cypher is trying to reuse the variable a (which would be bad.)

MATCH (a: Organisation), (b:Projekt) 
WHERE a.ORGA_ID= '926785240' AND b.PROJEKT_ID= '207481'
MERGE (a) - [r: Arbeit { Foerdersumme_in_EUR:' ' ,TIE_BY_ATTRIBUTE_1: '' ,TIE_BY_ATTRIBUTE_2: '' } ] -> (b)

;  // I think you need this semi colon

MATCH (a: Organisation), (b:Projekt) 
WHERE a.ORGA_ID= '' AND b.PROJEKT_ID= '03F0622A_BMBF'
MERGE (a) - [r: Arbeit { Foerdersumme_in_EUR:' xxxx' ,TIE_BY_ATTRIBUTE_1: '' ,TIE_BY_ATTRIBUTE_2: '' } ] -> (b)

I agree with @clem! You just need to add the semicolon and run in Cypher-shell or enable multi-statement query editor (as a screenshot) in the neo4j browser. Hope this helps