使用com.couchbase.client, java-client版本2.2.7,我无法使用包含多项的IN语句的n1ql查询,请参阅下面的示例查询和java代码
public int getCountForDuration(Long startTime, Long endTime, String ids){
JsonObject placeHolders = JsonObject.create().put("ids", ids).put("startTime", startTime).put("endTime", endTime);
N1qlQuery query = N1qlQuery.parameterized(COUNT_STATEMENT, placeHolders)
N1qlQueryResult result = bucket.query(query);
...
}
public static final String COUNT_STATEMENT = "select count(*) as count " +
"from bucketName " +
"where docType = 'docId' " +
"and (id IN [$ids]) " + <----- OFFENDING LINE
"and publishTimestamp between $startTime and $endTime";我尝试使用(')、(")和(‘)设置ids,例如:
ids = "'123', '456'";
ids = "\"123\" , \"456\";
ids = "`123`,`456`"; 当存在多个it时,所有这些都不起作用,但是,如果只有一个it,如ids = "'123'",则可以正常工作。而且,如果我在终端上使用CBQ,我的查询也能工作。
我的问题是,如何设置参数化的N1QL查询,它可以在in语句中接受多个项?
发布于 2016-08-02 07:48:55
删除语句中$ids周围的括号并将实际ids作为JsonArray对象放入JsonArray对象应该可以:
JsonObject placeHolders = JsonObject.create()
.put("ids", JsonArray.from("id1", "id2", "id3"))
.put("startTime", startTime)
.put("endTime", endTime);https://stackoverflow.com/questions/38711985
复制相似问题