因此,对于空数据库,MERGE (N1:A {name:"A"})-[:r]->(N2:B {name:"B"})
将创建两个节点 N1
和 N2
,它们之间有一条边 r
。然而,下面的 python 代码没有这样做...但是为什么呢?不应该吗?
from py2neo import Graph, authenticate, rel, Node
graph = Graph()
# set up authentication parameters
authenticate("localhost:7474", <user>, <password>)
# clear the data base
graph.delete_all()
graph.merge(rel(Node("A" , name="A"), "r", Node("B" , name="B")))
运行该脚本会导致数据库仍然是空的。为什么会这样?如何在不使用 graph.cypher.execute("MERGE ...")
的情况下从 py2neo 获取 Cypher 合并行为?
最佳答案
在 Py2neo 中 graph.merge
通过标签和(可选)属性匹配或创建单个节点,您希望在整个模式(节点、关系、其他节点)上合并。
您在 Cypher MERGE
语句中使用的模式在 Cypher 之外的 Py2neo 中似乎不受支持。
关于python - py2neo graph.merge() 的行为与 Cypher MERGE 不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36103391/