I have a table with a collection of ids (sqlite Android), and a collection of ids I want to retain.
Then if toRetain = [1,2,3,4] I create an execute:
DELETE FROM my_items WHERE _id NOT IN (1,2,3,4);
But if the length of the items to retain is very high the SQL engine throws an exception: “too many SQL variables”. Since the clause is NOT IN I can’t do it in smaller steps.
How can i solve it?
One solution I think is to insert all the ids in a temporal table and then execute:
DELETE FROM my_items WHERE _id NOT IN (SELECT_id FROM items_to_delete);
Is that solution correct and efficient??
I think creating a temp table or table variable and then insert all the ids to be retained in that. Then delete from the main table by joining main table with this temp or table variables.
Here I suggest to create an index if you use temp table also use the inner join insted of NOT IN