SQLITE DELETE FROM row WHERE id IN (?) removes only firs item

Tags: ,



I’m trying to delete multiple rows based on array of ids. The query is:

// id INTEGER PRIMARY KEY AUTOINCREMENT

executeSql(`DELETE FROM row WHERE id IN (?)`, [1,2,3])

However, it removes only first row with ID of the array and ignores the rest(2 and 3 are not removed); if I try to remove rows based on non-primary key like this

executeSql(`DELETE FROM row WHERE anotherId IN (?)`, [1,2,3])

everything works.

What am I missing here?

P.S. There are work arounds for this like DELETE FROM row WHERE id=1 OR id=2 OR id=3; however, I would like to understand why it doesn’t work using IN and not looking for alternative solutions.

Answer

You need to transform your array into comma seperated strings.

Similar example:

Delete multiple rows using IDs?



Source: stackoverflow