【问题标题】:How to use date time as a cluster in where clause in Cassandra using python driver?如何使用 python 驱动程序在 Cassandra 的 where 子句中使用日期时间作为集群?
【发布时间】:2018-04-12 12:55:06
【问题描述】:

我正在使用 python 驱动程序和 Cassandra,我创建了以下架构

CREATE TABLE channelFollowers(
    channelID BIGINT,
    isfavorite BOOLEAN,                     
    userID BIGINT,                                                          
    followDate TIMESTAMP,
    PRIMARY KEY (userID, channelID, followDate)
);

我的问题是,我如何在 select 和 update 查询的 where 子句中使用 followDate,我已经尝试过但它不起作用,它给出了以下错误

typeerror: not enough arguments for format string

任何人都可以帮助我吗?

这是我的代码 channelLike = channelSession.execute("update channelfollowers set isblocked=%s, isfavorite=%s where userid=%s and channelid=%s and followdate=%s",[int(userid),int(channel_id),followDate]

【问题讨论】:

  • 显示您的代码。
  • 我已经更新了我的问题

标签: python cassandra cassandra-python-driver


【解决方案1】:

从我在错误消息和您的代码中看到的 - 您在格式字符串 (%s) 中有 5 个占位符,但只传递了 3 个值。我相信您省略了 isblocked 和 isfavorite 参数的占位符 - 要么传递它们,要么将 %s 替换为真/假值(从查询中可以看出,它们应该具有布尔类型)

附:您在表的定义中也没有isblocked

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-08
    • 2013-03-02
    • 1970-01-01
    • 2015-05-13
    • 1970-01-01
    • 2013-04-23
    • 1970-01-01
    相关资源
    最近更新 更多