Cypher Upsert?

903 views
Skip to first unread message

Ben Titmarsh

unread,
Feb 7, 2014, 10:58:19 AM2/7/14
to ne...@googlegroups.com
Hello,

Is it possible to write a semantic Upsert, i.e. update or insert if it doesn't exist using one cypher query?

To give a bit of context, this is what I'm doing:

MATCH (fromCard:Card)-[r:DECK_INCIDENCE]-(toCard:Card)
WHERE fromCard.name in {...} and toCard.name in {...}
SET r.passCount = r.passCount+1

If the property passCount doesn't exist yet on the relationship then I'd like to set it to 1.

Is it possible to achieve an upsert using one query?

Cheers,
Ben.

Alistair Jones

unread,
Feb 7, 2014, 11:04:37 AM2/7/14
to ne...@googlegroups.com
Hi Ben,

Have you looked at MERGE?

-Alistair



--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Ben Titmarsh

unread,
Feb 7, 2014, 11:54:08 AM2/7/14
to ne...@googlegroups.com
Thanks Alistair.

Your advice directed me to the Cypher refcard (http://docs.neo4j.org/refcard/2.0/) where I ended up finding the coalesce function which does exactly what I need:

SET r.passCount = coalesce(r.passCount, 0) +1
Reply all
Reply to author
Forward
0 new messages