End UNWIND statement in a Cypher Query

纵然是瞬间 提交于 2019-12-31 02:46:22

问题


If I have a cypher query that unwinds a parameter, everything after that portion of the query is called x number of times of the unwind. I'd like to figure out a way to end the unwind and continue with other things.

MATCH (thing:Thing)
UNWIND { names } AS name
CREATE thing-[:HAS_NAME]-(n:Name {name: name})
//done with the unwind
WITH (thing)
CREATE thing[:HAS_AGE]-(a:Age {age: 20})

In the above example, I will end up with two thing-[:HAS_AGE]->() relationships because of the unwind. Do I have to split this into separate statements?


回答1:


After the unwind you have two rows. If you re-collapse thing before moving on you will then have a single again.

MATCH (thing:Thing)
UNWIND { names } AS name
CREATE thing-[:HAS_NAME]-(n:Name {name: name})
//done with the unwind
WITH distinct thing
CREATE thing[:HAS_AGE]-(a:Age {age: 20})


来源:https://stackoverflow.com/questions/30744331/end-unwind-statement-in-a-cypher-query

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