Search code examples
pythoncassandracassandra-python-driver

How to use date time as a cluster in where clause in Cassandra using python driver?


I am using python driver and Cassandra, I have created the following schema

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

my question is, how can i use the followDate in where clause of select and update query, I have tried but it does not work it gives the following error

typeerror: not enough arguments for format string

can any body help me please?

Here is my code 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]


Solution

  • From what I see in the error message & in your code - you have 5 placeholders in format string (%s), but pass only 3 values. I believe that you omit placeholders for isblocked & isfavorite parameters - either pass them, or replace %s with true/false values (as I can see from query, they should have boolean type)

    P.S. you also don't have isblocked in the table's definition