I'm having trouble with a cypher query. I want to replace one or more relationships, if they 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?:RELATED]->(s)
FOREACH (u in (CASE WHEN r<>NULL THEN [u] ELSE [] END):
CREATE (u)<-[:REL1]-(n {test:"test"})-[:REL2]->(s))
DELETE r
RETURN sI get an error saying:
Unknown identifier n
Does anyone know how to fix this?