错误使用cypher集合(同时创建一个节点链)

时间:2014-12-17 09:14:06

标签: neo4j cypher

我做了一个查询,通过将一个p节点的有序集合附加到C节点来创建一个节点链(如果它们都具有相同的id,在我们的例子中是'-670')。创建有序的p节点集合没有问题,但我在行CREATE(c)<-[:RELATED_TO]-(Ps[0])完整查询中出错了

MATCH (c:C{id: -670}), (p:P{id:-670})
WHERE not(p-[:RELATED_TO]->())
WITH p, c 
ORDER BY p.t_start
with collect(p) as Ps, c

//This create doesn't work
CREATE (c)<-[:RELATED_TO]-(Ps[0])

//This create works fine
FOREACH(i in RANGE(0, length(Ps)-2) |
FOREACH(pay1 in [Ps[i]] |
FOREACH(pay2 in [Ps[i+1]] |
CREATE UNIQUE (pay1)<-[:RELATED_TO]-(pay2))))

RETURN Ps, c

错误:“无效输入'[':预期标识符字符,节点标签,属性映射,空格或')'(第6行)”

这是我第一次在cypher中使用集合,我真的不知道它有什么问题。提前致谢

1 个答案:

答案 0 :(得分:2)

这个怎么样?

MATCH (c:C{id: -670}), (p:P{id:-670})
WHERE not(p-[:RELATED_TO]->())
WITH collect(p) AS ps, c 
ORDER BY p.t_start
WITH p[0] AS p0, c
CREATE (c)<-[:RELATED_TO]-(p0)

你可能可以逃脱:

WITH collect(p)[0] AS p0, c

虽然我没试过那个