【发布时间】:2017-02-07 03:16:25
【问题描述】:
如果我在 neo4j 数据库上运行我的 python 脚本,可以正常工作:
从 py2neo 导入节点、关系、图形、密码、身份验证 # 设置认证参数 验证(“本地主机:7474”,“用户”,“密码”) # 连接到经过身份验证的图形数据库 sgraph = Graph("http://localhost:7474/db/data/") a=raw_input("输入名称 A:") b=raw_input("输入名称 B:") 图 = 图() tx = graph.cypher.begin() tx.append("MATCH (c:Person {name:{a}}), (d:Person {name:{b}}) 创建 (c)-[:KNOWS}]->(d)", a= a, b=b) tx.commit()但是,当我尝试向关系添加参数时...:
a=raw_input("Input Name A: ")
b=raw_input("Input Name B: ")
z=raw_input("Input parameter of relationship z: ")
x=raw_input("Input parameter of relationship x: ")
graph = Graph()
tx = graph.cypher.begin()
tx.append("MATCH (c:Person {name:{a}}), (d:Person {name:{b}}) CREATE (c)-[:KNOWS{labelz:{z},labelx:{x}}]->(d)", a=a, b=b)
tx.commit()
我知道了:
tx.commit() 提交中的文件“/usr/local/lib/python2.7/dist-packages/py2neo/cypher/core.py”,第 333 行 返回 self.post(self.__commit 或 self.__begin_commit) 文件“/usr/local/lib/python2.7/dist-packages/py2neo/cypher/core.py”,第 288 行,在 post raise self.error_class.hydrate(error) py2neo.cypher.error.statement.ParameterMissing:需要一个名为 z 的参数如何放置这些变量以避免错误? 提前致谢。
【问题讨论】:
-
您在查询结束时提供了
a和b的参数,但您没有提供z或x。只需添加它们。 -
你绝对正确,几分钟前测试我能够做到。抱歉打扰了。但我试图做的另一件事是将关系的标签作为参数引入,在本例中为“KNOWS”,即使包括在查询末尾也不起作用。
-
在这种情况下,使用字符串连接将关系类型动态添加到查询中可能是个好主意。或者,如果您安装 APOC 过程,则可以使用 apoc.create.relationship() 来创建关系,而不是使用 CREATE。这将让您为关系类型提供一个字符串。
标签: python neo4j cypher py2neo