这是我的列族定义:
CREATE TABLE columnfamily (column1 int PRIMARY KEY, column2 text);
我正在使用 python cassandra-dbapi2 1.4.0 连接到 Cassandra 1.1.6,使用 CQL 3 语法。我想对以下查询使用查询替换,但它似乎不适用于 WHERE... IN (...,...):
cql = "SELECT * FROM columnfamily WHERE column1 IN (:x) and column2 = :y;"
q = cursor.prepare_query(cql)
cursor.execute_prepared(q, {'x':(1,2,3), 'y':'abc'}
尝试上述方法后出现以下错误:
Traceback (most recent call last):
File "test_cassandra.py", line 17, in <module>
cursor.execute_prepared(q, params)
File "/usr/local/lib/python2.7/dist-packages/cql/cursor.py", line 89, in execute_prepared
response = self.get_response_prepared(prepared_query, params, cl)
File "/usr/local/lib/python2.7/dist-packages/cql/thrifteries.py", line 83, in get_response_prepared
paramvals = prepared_query.encode_params(params)
File "/usr/local/lib/python2.7/dist-packages/cql/query.py", line 60, in encode_params
return [t.to_binary(t.validate(params[n])) for (n, t) in zip(self.paramnames, self.vartypes)]
File "/usr/local/lib/python2.7/dist-packages/cql/cqltypes.py", line 225, in to_binary
return cls.serialize(val)
struct.error: cannot convert argument to integer
我也尝试过使用以下内容:
cursor.execute_prepared(q, {'x':','.join([str(i) for i in (1,2,3)]), 'y':'abc'}
发生了同样的错误。有谁知道在 WHERE ... IN (...,...) 语句中进行查询替换的正确方法是什么?
谢谢!