Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Room Persistence Library - How to find entities with ids contained in list of ids?

I am trying to do the following query in my DAO.

   @Query("SELECT * FROM objects WHERE obj_id IN :ids")
   List<Object> queryObjects(List<String> ids);

It gives me this compile-time error:

Error: no viable alternative at input 'SELECT * FROM objects WHERE obj_id IN :ids'

Both List<String> ids as well as String... ids and Sring[] ids don't work. However, since I don't know how many ids I will have in compile-time and therefore, I need a list/array and not varargs.

How can I make this SQL query work?

like image 738
rgoncalv Avatar asked Jan 21 '18 18:01

rgoncalv


1 Answers

You need parentheses:

@Query("SELECT * FROM objects WHERE obj_id IN (:ids)")
List<Object> queryObjects(List<String> ids);

(and FWIW, I filed an issue to try to get a better error message here)

like image 92
CommonsWare Avatar answered Oct 17 '22 20:10

CommonsWare