I am trying to use a prepared statement to query keyspaces via python's cassandra driver.
This is the query and it's preparation...
from cassandra.cluster import Cluster
cluster = Cluster(
**conn_details
)
session = cluster.connect("mykeyspace")
query = ("SELECT timestamp "
"FROM mykeyspace.mytable "
"WHERE t_id='123' "
"AND p_id='321' "
"AND timestamp IN ? "
)
prepared_statement = session.prepare(query)
session.execute(prepared_statement, parameters=[ (1677145736507, 1677145728972) ]).current_rows
The output is an empty list. There is some issue with the statement binding as I'm able to run the CQL IN with success in three scenarios below... i.e. if I run the below raw query via session.execute(<raw query string>)
I can get a response..
SELECT timestamp
FROM mykeyspace.mytable
WHERE t_id='123'
AND p_id='321'
AND collection_event_timestamp IN (1677145728972, 1677145736507)
If I run inside the keyspaces query editor on AWS I get the expected response
The only way I can get IN to work with any parameterisation is via string formatting..
id_tuples = (1677145736507, 1677145728972)
query = "SELECT timestamp FROM mykeyspace.mytable WHERE t_id='123' AND p_id='321' AND timestamp IN %s "
session.execute(query, parameters=[ValueSequence(id_tuples)]).current_rows
Does anyone have any advice as to what is going wrong here? Why is the prepared statement approach not working?