Getting a syntax error I don't understand


(Michael Porter) #1

I'm using the latest versions of neo4j desktop and database. I'm doing some development locally and using this query:

match (w:Well)
where w.operator is not null
with w.operator as well_o
merge (o:Operator {name: well_o})
set (o)-[:OPERATES]->(w)
return o, w

I'm getting this error:

Neo.ClientError.Statement.SyntaxError: Invalid input 'r': expected whitespace, comment, a relationship pattern or '.' (line 6, column 1 (offset: 129))
"return o, w"
 ^

If I run the first half of the query it creates the operator nodes no problem. Am I running too many operations in one go? I'm not quite sure what else it's expecting.


(Sylvainroussy) #2

Hi !

Must be:
{name: "well_o"}

With quotes.


(Michael Porter) #3

Thanks for the reply, I appreciate the help but that did not work. I'm still getting the same error as before.


(Michael Porter) #4

I was able to return the pairs I wanted to return with:

match (w:Well)
match (o:Operator)
where w.operator = o.name
return o, w

but if I try to set a relationship between them I get errors.

match (w:Well)
match (o:Operator)
where w.operator = o.name
set(o)-[r:OPERATES]->(w)
return r

(Sylvainroussy) #5

Brrr.. Poor me.

match (w:Well)
match (o:Operator)
where w.operator = o.name
MERGE (o)-[r:OPERATES]->(w)
return r

SET is for putting property or labels
Replace MERGE by MATCH if you don't want create the relationship.


(Michael Porter) #6

Ah, you just reminded me what I was really trying to do. You're a prince among men. Here's what I was really after, I just forgot exactly how.

match (w:Well)
match (o:Operator)
where w.operator = o.name
CREATE (o)-[r:OPERATES]->(w)
return r

I forgot to use Create vs. Merge and set. Thank you for your help.