4
這是我列族的定義:蟒蛇CQL查詢取代 「SELECT * FROM CF凡在列(.. .. ..)」
CREATE TABLE columnfamily (column1 int PRIMARY KEY, column2 text);
我使用python卡桑德拉 - dbapi2 1.4。 0使用CQL 3語法連接到Cassandra 1.1.6。我想在下面的查詢使用查詢替換,但似乎沒有工作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(...,...)語句中進行查詢替換的正確方法是什麼?
謝謝!