0
votes

I want to copy existing relationships to a new node. All nodes exist already and I would like to copy all incoming relationships to a second node. Given a node D and a graph like

A -[r]-> B <-[s]- C

I would like to create the following in a single Cypher query:

A -[r]-> B <-[s]- C
A -[r]-> D <-[s]- C

Only the relationships in the second line should be created, as all other nodes exist already. I have tried the following Cypher query (which is an Invalid query (Don't know how to extract parameters from this type: org.neo4j.kernel.impl.core.RelationshipProxy)):

START targetNode = node(42)
MATCH sourceNode -[r]-> targetNode
CREATE sourceNode -[s:TYPE(r)]-> targetNode
RETURN s
1
my hit (fill it with correct ids): start n1=node(B),n2=node(D) match sources-[r]->n1,n2 with sources,r,n2 relate sources-[r]->n2 return n2ulkas
Have you tried this? It seems to be an invalid query, as you cannot use a pattern like sources-[r]->n2 in a RELATE or CREATE UNIQUE queryFynn
no, i haven't. but it's the way it should be done. look at the docu: docs.neo4j.org/chunked/1.8.M03/query-relate.html . there is the pattern left-[r:KNOWS]->right in relate section.ulkas
The difference is, that this example works with a known relationship type (:KNOWS). My question is aimed at creating the relationships with different types.Fynn

1 Answers

0
votes

There doesn't exist any good way to do this today. It's a very reasonable use case though, so I would encourage you to raise an issue about it here: https://github.com/neo4j/community/issues

Thanks for sharing!

Andrés