简体   繁体   中英

django cassandra not executing select query with where clause for datetime range

I have data in cassandra and I am trying to fetch data from the DB within a datetime range.

Below is the code.

fromdate = datetime.combine(dt, datetime.min.time())
todate = datetime.combine(datetime.now().date(), time(23, 59, 59))
print(fromdate)
print(todate)

batch = BatchStatement()
batch.add(SimpleStatement("SELECT * FROM datadump WHERE 'pickup_time' >= '%s' AND 'pickup_time' <= '%s' ALLOW FILTERING;"),
              (fromdate, todate,))
data = session.execute(batch)

The above code does not work when I try to fetch data within a datetime range but if I try to fetch all the data like "SELECT * from datadump" it works.

Can someone please let me know what's wrong with the above approach?

Thanks in advance!

You can't use SELECT in the batch statement - it's only for INSERT / UPDATE / DELETE ...

Also, please note that BATCH in CQL is different than in SQL, and you need to know when to use it, and when not - please refer to the documentation on how & when to use it .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM