How to query using In operator in Ignite Cache

46 Views Asked by At

I have an Ignite cache that I am using as table and I want to update multiple rows of that table using a single query. When I use the In operator it's only working for 1 value and it fails for all others.

From what I understood, In operator does not support var args and only 1 value is accepted. A lot of solutions point to creating a temp table and using that table for In clause.

So my question is - how to create a temp table if there is a way and how to populate the temp table with list of values at once?

2

There are 2 best solutions below

0
On

IN operator does not have the "1 value" limitation.

SELECT * from mytable where id in (1,2,3) 

works well.
Ignite doesn't have a concept of a "temp table". If you would like to go that route, create a regular table using "CREATE TABLE" command

0
On

You don't give a lot of context, but I assume you have a query like this:

select * from table where id in (?)

And you have one or more values in the query parameter?

If that's it, the trick is to rewrite the query:

select t.* from table t join table(id bigint = (?)) i on t.id = i.id 

Then you pass in your list as an array:

var q = new SqlFieldsQuery("...")
           .setArgs((Object[]) new Integer[] { 1, 2, 3 });