Neo4J create temp variable within Cypher

后端 未结 2 1222
名媛妹妹
名媛妹妹 2021-01-18 17:23

So my Top-Level problem is I am trying to return whether a MERGE resulted in the creation of a new Node or not.

In order to do this I was thinking I cou

相关标签:
2条回答
  • 2021-01-18 18:09

    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;
    
    0 讨论(0)
  • 2021-01-18 18:10

    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
    
    0 讨论(0)
提交回复
热议问题