I have a requirement to delete a relationship alone(not nodes) if exists and then create a new relationship with existing nodes. All two operations should occur in a single statement. Am able to delete and create at the same time, only when a relationship exists between the nodes else if there is no relationship exists statements are not executing after the delete call.
Am using apoc.do.case()
You probably don't need to use an apoc function for that, a simple MATCH
should suffice:
MATCH (a)-[r:old_type_of_rel]->(b)
DELETE r
CREATE (a)-[:new_type_of_rel]->(b)
If the entire match statement doesn't pass (e.g both nodes and the relationship between them must exists) then neither the DELETE
nor CREATE
will execute.
If relationship may or may not exist then you can try this
OPTIONAL MATCH (a)-[r:old_type_of_rel]->(b)
DELETE r
CREATE (a)-[:new_type_of_rel]->(b)