I want to replace a relationship, if it exists, with a new node and two new relationships. The query below tests if the relationship exists but it fails on the new node creation. The CREATE syntax works on its own but not nested within the FOREACH loop.
START s = node(1)
MATCH (u)-[r?:ROOT]->(s)
FOREACH (u in (CASE WHEN r<>NULL THEN [u] ELSE [] END):
CREATE (u)<-[:REL1]-(n {test:"test"})-[:REL2]->(s))
RETURN s
I get an error saying:
Unknown identifier n