New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request : apoc support for MERGE for nodes and rels #271

Open
ophileon opened this Issue Feb 10, 2017 · 5 comments

Comments

6 participants
@ophileon

ophileon commented Feb 10, 2017

It would be nice to be able to include MERGE operations in apoc

 CALL apoc.merge.node(mergeLabel,{id:mergeId}) YIELD node
 RETURN node

We now have to use this workaround

 WITH 'MERGE (n:mergeLabel {id:mergeId}) return n' AS cypher
 CALL apoc.cypher.doit(cypher,{}) yield value
 RETURN value.n

And for rels:

apoc.merge.relationship(from,to,relType) yield rel
@cstaikos

This comment has been minimized.

cstaikos commented May 2, 2017

@ophileon can you clarify how the workaround you described works? I've tried the following:

 WITH 'MERGE (n:mergeLabel {id:mergeId}) return n' AS cypher
 CALL apoc.cypher.doit(cypher,{mergeLabel: 'myNewLabel', mergeId: 123}) yield value
 RETURN value.n

But this seems to create a node with label mergeLabel, instead of myNewLabel - the node does get an id of 123 however.

Edit: For context, I want to pass in values for mergeLabel from a FOREACH or UNWIND.

@InverseFalcon

This comment has been minimized.

Collaborator

InverseFalcon commented May 2, 2017

I think you'd need to use string appending here, for a dynamic node label:

WITH 'MERGE (n:' + mergeLabel + ' {id:mergeId}) return n' AS cypher
CALL apoc.cypher.doit(cypher,{mergeId: 123}) yield value
RETURN value.n
@cstaikos

This comment has been minimized.

cstaikos commented May 2, 2017

@InverseFalcon perfect, that did it! Thanks!

@jexp jexp moved this from Backlog to Done in Larus Development Aug 4, 2017

@arganzheng

This comment has been minimized.

arganzheng commented Nov 21, 2017

from this article: Summer 2017 Release of the APOC Procedures Librar, it seem thats apoc has already support merge nodes and relationship.

There are now procedures to merge nodes and relationships with dynamic labels, relationship-types, and properties (apoc.merge.node/relationship).

CALL apoc.merge.node(['Label'], {id:uniqueValue}, {prop:value,...}) YIELD node;
CALL apoc.merge.relationship(startNode, 'RELTYPE', {[id:uniqueValue]}, {prop:value}, endNode) YIELD rel;
@victoriastuart

This comment has been minimized.

victoriastuart commented Apr 7, 2018

I see that this APOC procedure,

CALL apoc.merge.relationship(startNode, 'RELTYPE', {[id:uniqueValue]}, {prop:value}, endNode) YIELD rel;

appears here:

but not here:

Just curious: is there a reason why it has not been added to the latter site?

It solves an issue described here, https://stackoverflow.com/questions/49682338/creating-a-metabolic-pathway-in-neo4j/49684460#49684460, re: re-iteration of apoc.create.relationship(...) and the addition of duplicate relations (one per iteration).

@jexp jexp added the docs label Apr 11, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment