0

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
Fynn
  • 4,753
  • 3
  • 32
  • 69
  • 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 n2 – ulkas Sep 17 '12 at 11:58
  • 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` query – Fynn Oct 01 '12 at 15:49
  • no, i haven't. but it's the way it should be done. look at the docu: http://docs.neo4j.org/chunked/1.8.M03/query-relate.html . there is the pattern left-[r:KNOWS]->right in relate section. – ulkas Oct 02 '12 at 09:43
  • 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 Oct 02 '12 at 09:49

1 Answers1

0

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

Andres
  • 1,454
  • 11
  • 12
  • As there seems to be no possibility using cypher, what would be the best solution using another method, e.g. the [Neo4j API](http://api.neo4j.org/1.8.M06/)? – Fynn Sep 12 '12 at 14:07
  • it is now in the current 1.9.M01 release you can `SET` properties from other nodes and relationships. – Michael Hunger Oct 28 '12 at 02:17