我想像通过 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/