Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
05-20-2020 11:26 PM
Hello again!
I have a relatively simple problem I can't figure out. I'm trying to "merge" relationships over from one node to another node with relationships of its own; Ideally, if the below worked I'd be in the clear but I get "variable r2 already defined" ;(
match (n:user {other_id:"me"})-[r]-() with r, n
match (temp:user {btcID: n.ID}) where not exists(temp.other_id) match (temp)-[r2]-()
Create / Merge (n)-[r2]-(z) //or set r = r + r2
detach delete temp
return n
I'm trying to append the matched relationships connected to the temp node, switch them over to the existing "me" node, and then delete the temp node. Is there a way to do this without apoc?
Thanks again, really appreciate all thehelp received here 😄
Solved! Go to Solution.
05-21-2020 10:27 AM
MATCH (n:user {other_id:"me"})-[r]-()
MATCH (temp:user {btcID: n.ID})
WHERE NOT exists(temp.other_id)
MATCH (temp)-[r2]-(tgt)
MERGE (n)-[rNew]-(tgt)
ON CREATE SET rNew=r2 # will copy all properties over
ON MATCH SET rNew=r2 # what to do with old r props? keep, replace, sum?
DETACH DELETE temp
RETURN n
05-21-2020 05:52 AM
Hello @racket8484,
The relationship you want to create in the MERGE clause must be new so you cannot use the r2
one, but if you want to copy the data in it, you can extract them with a WITH
clause and after the MERGE, you can SET
the relation:)
Regards,
Cobra
05-21-2020 10:27 AM
MATCH (n:user {other_id:"me"})-[r]-()
MATCH (temp:user {btcID: n.ID})
WHERE NOT exists(temp.other_id)
MATCH (temp)-[r2]-(tgt)
MERGE (n)-[rNew]-(tgt)
ON CREATE SET rNew=r2 # will copy all properties over
ON MATCH SET rNew=r2 # what to do with old r props? keep, replace, sum?
DETACH DELETE temp
RETURN n
All the sessions of the conference are now available online