Getting a syntax error I don't understand

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.

Hi !

Must be:
{name: "well_o"}

With quotes.

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

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

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.

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.

1 Like

CREATE p=(MATHI{name:"SRIMATHI"})-[r:topper_of]-[]->(TAMIL{name :"TAMILNADU"})-[]->[r:winner_of]-[*]->(cse{name:"ANNA UNIVERSITY IN CSE DEPT"})
RETURN p

i dont get whats the error

Welcome Joyous,

Do you might adding what error your getting? It's difficult helping without knowing what you're getting.

Remember, you need to be explicit when you'are creating nodes. Or you give some empty types for relationships ( --> and star (-[*]->).