python - 无法在 COALESCE pypher 中设置列​​表类型值

标签 python neo4j cypher coalesce py2neo

我想像通过 pypher 一样构建查询

set entity.birth_date = coalesce(VALUE + entity.birth_date, entity.birth_date , [] + VALUE)

VALUE 是类似“38”的字符串

我尝试过的是:

from pypher import Pypher, __
p = Pypher()
p.Merge.node('ent', **node_gr)
p.SET(__.ent.__birth_place__ == __.COALESCE(__.ent.__birth_place__+ 
VALUE,__.ent.__birth_place__,[VALUE]))

它抛出以下错误:

python3.6/site-packages/pypher/builder.py in bind_param(self, value, name)
    196                     name = k
    197                     break
--> 198         elif bind and value in self._bound_params.keys():
    199             for k, v in self._bound_params.items():
    200                 if k == value:

TypeError: unhashable type: 'list'

我还尝试将 [VALUE] 转换为字符串,但更新后的值与字符串不正确

最佳答案

Pypher 提供了 __.List 函数来根据值构造列表。例如,以下内容:

p.SET(__.ent.__birth_place__ == __.COALESCE(__.ent.__birth_place__ + VALUE,__.ent.__birth_place__, __.List() + VALUE))

产生类似于:

MERGE (ent:`MyNode`) SET ent.`birth_place` = coalesce(ent.`birth_place` + $NEO_5288d_0, ent.`birth_place`, [] + $NEO_5288d_0)

虽然 List 采用一个参数来构造列表,但更好的方法可能是:

p.SET(__.ent.__birth_place__ == __.COALESCE(__.ent.__birth_place__ + VALUE,__.ent.__birth_place__, __.List(VALUE)))

这会产生类似的结果:

MERGE (ent:`MyNode`) SET ent.`birth_place` = coalesce(ent.`birth_place` + $NEO_e2895_0, ent.`birth_place`, [$NEO_e2895_0])

关于python - 无法在 COALESCE pypher 中设置列​​表类型值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57924653/

相关文章:

neo4j - SyntaxError, "Unknown procedure output: ` node`"是什么意思?

python - 使用 Pandas 按键获取组名的最快方法是什么?

python - 将 pandas DataFrame reshape 为 Series 元素

ubuntu - Neo4j 远程访问问题

neo4j - 在 unix : mac or linux 中离线备份 neo4j 社区版

neo4j - 获取每个关系深度的节点数

neo4j - 查找未设置属性的Neo4j节点

python - 如果相同的连续值,则按一天的剩余时间分组以显示 True

python - 尝试导入本地模块时,worker 上出现 ModuleNotFoundError #222

java - 在 Neo4j 嵌入式 java 中通过 ID 获取节点或关系