【问题标题】:Problem with python driver in Cassandra when use prepared statements使用准备好的语句时,Cassandra 中的 python 驱动程序出现问题
【发布时间】:2020-09-28 15:53:52
【问题描述】:

当我想使用以下 python 代码更新 Cassandra 表中的设置项时

ps = session.prepare( """ UPDATE test,tbl SET val = val + {'?'} where name = ? and id = ?;""" )
bs = bind(ps, ['name', 'name', 1])
session.execute(bs)

我有错误

Too many arguments provided to bind() (got 3, expected 2)

问题是准备好的无法识别的{'?'}。我测试 {\'?\'} 但没有任何改变。

【问题讨论】:

  • 您可以编辑您的帖子以包含您的表格定义吗?

标签: python cassandra cassandra-driver


【解决方案1】:

更新:忘记了那个语法...

您需要使用以下语法:

UPDATE test,tbl SET val = val + ? where name = ? and id = ?;

并以 set 作为第一个参数进行绑定:

bs = bind(ps, [set(['name']), 'name', 1])

原答案:

您不需要在 ? 字符周围加上引号 - 当绑定发生时,它会正确地引用文本和其他类型。

附:请注意,如果你使用{?},这意味着你总是在集合中插入一个元素。如果你需要更多,那么你只需要使用?,并传递一个 python 集作为参数。

【讨论】:

  • 当我删除报价单时?我收到以下错误 val 的无效集文字:集合文字中不支持绑定变量
猜你喜欢
  • 2017-11-05
  • 2018-06-07
  • 1970-01-01
  • 2016-07-02
  • 2013-05-31
  • 2015-04-30
  • 2013-07-10
  • 1970-01-01
  • 2015-06-23
相关资源
最近更新 更多