shubhendra sen
shubhendra sen

Reputation: 206

Apache Ignite cache "IN" clause not working

What I want to do is

    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();

. It is not giving the desired result. It is returning only one result instead of two.
Please suggest

Upvotes: 0

Views: 810

Answers (1)

Denis Mekhanikov
Denis Mekhanikov

Reputation: 3591

It's impossible to pass an array as an argument for in. You can rewrite your query to use a join instead. It will look as follows:

select u.userName from users u 
    join table (userId bigint=?) t on u.userId=t.userId 
where u.isActive=1

Another thing you should take into account is that SqlFieldsQuery.setArgs(...) takes a vararg as an argument. So, to prevent your array from being unfolded, you should add a cast to Object:

sql.setArgs((Object)userIds.toArray());

Upvotes: 2

Related Questions