Prepared Statement with collection in IN clause in Datastax Cassandra CQL driver

我的未来我决定 提交于 2019-11-27 16:03:47

问题


I am trying to run the following query

SELECT edge_id, b_id FROM booking_by_edge WHERE edge_id IN ?

I bind Java list of Long's as a parameter and I get an exception

SyntaxError: line 0:-1 mismatched input '<EOF>' expecting ')' (ResultSetFuture.java:242)

If I try to use (?) it expects single Long item to be bound, but I need a collection

Is there an error in my syntax?


回答1:


Tested in Cassandra 2.1.3, the following code snippet works:

PreparedStatement prepared = session.prepare("SELECT edge_id, b_id FROM booking_by_edge WHERE edge_id IN ?;");
List<Long> edgeIds = Arrays.asList(1L, 2L, 3L);
session.execute(prepared.bind(edgeIds));



回答2:


Got response on Datastax bugzilla, it is currently not supported, but planned

https://issues.apache.org/jira/browse/CASSANDRA-4210

Update: Supported in Cassandra 2.0.1




回答3:


It's a bit hard to find in the documentation but it is described in the tuples section of the manual.

If you want to use named parameters you should use the setList() method.

BoundStatement bs = session.prepare("select col from table where col in :values").bind();
bs.setList("values", Arrays.asList(v1, v2, v3));


来源:https://stackoverflow.com/questions/16918853/prepared-statement-with-collection-in-in-clause-in-datastax-cassandra-cql-driver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!