[英]Apache Ignite cache "IN" clause not working
我想做的是
final String query = "select userName from users where userId in
(?) and isActive = 1";
SqlFieldsQuery sql = new SqlFieldsQuery(query);
List<Long> userIds = new ArrayList<Long>();
userIds.add(140l);
userIds.add(245l);
sql.setArgs(userIds.toArray());
List<List<?>> rsList = usersCache.query(sql).getAll();
. 它沒有給出預期的結果。 它只返回一個結果而不是兩個。
請建議
不可能將數組作為in
的參數傳遞。 您可以重寫查詢以改用聯接。 它將如下所示:
select u.userName from users u
join table (userId bigint=?) t on u.userId=t.userId
where u.isActive=1
您應該考慮的另一件事是SqlFieldsQuery.setArgs(...)
將 vararg 作為參數。 因此,為了防止您的數組被展開,您應該向Object
添加一個強制轉換:
sql.setArgs((Object)userIds.toArray());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.