Cypher Neo4J - CASE Expression with MERGE

后端 未结 4 1212
伪装坚强ぢ
伪装坚强ぢ 2020-11-30 11:25

I\'m trying to implement the logic in Cypher where, based on a particular condition (CASE Statement), I would create some nodes and relationships; the code is

4条回答
  •  鱼传尺愫
    2020-11-30 12:08

    The APOC plugin supports Conditional Cypher Execution, which now allows us to avoid the FOREACH workaround.

    For example, you can do this:

    MATCH (g:Game)-[:PLAYER]->(u:User)-[r1:AT]->(b1:Block)-[:NEXT]->(b2:Block) 
    WHERE g.game_id='G222' AND u.email_id = 'xyz@example.com' AND b1.block_id='16' 
    SET r1.status='Skipped', r1.enddate=20141225
    WITH u, b2, g
    CALL apoc.do.when(
      b2.fork = 'y',
      "MERGE (u)-[:STAGE {startdate:20141225, enddate:'99999999', status:'InProgress'}]->(b2     {fork:'fail'})",
      "MERGE (u)-[:STAGE {startdate:20141225, enddate:'99999999', status:'InProgress'}]->(b2)",
      {u: u, b2: b2}) YIELD value
    WITH u, g
    MATCH (u)-[:TIME]->(h:Time)<-[:TIME]-(g)
    SET h.after = 0
    SET h.before = h.before + 1
    

提交回复
热议问题