Neo4J create temp variable within Cypher

别来无恙 提交于 2019-12-01 21:04:10
FrobberOfBits

You can do what you want, here's how (combination of my first answer, with @cybersam's addition). You just do it with a node property you create and then remove, instead of an unbound variable as you've been trying.

MERGE(tom:Person {id:'Tom Jones'})
ON CREATE set tom.temp_bool = true
ON MATCH set tom.temp_bool = false
WITH tom, tom.temp_bool AS result
REMOVE tom.temp_bool
RETURN result;

In simple merging cases like this where maximum one node could be created, a cleaner way to achieve what you are looking for could be checking the result stats. I case of using Bolt API you should check:

results.consume().counters.nodes_created = 1
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!