Rogach Rogach - 2 months ago 24
Scala Question

Is it possible to use IN clause in plain sql Slick?

For example, I want to create the following query:

SELECT c.* FROM Coffees c WHERE c.name IN ('robusta', 'arabica')


My attempt failed:

val cnames = List("robusta", "arabica")
sql""" SELECT c.* FROM Coffees c WHERE c.name IN ${cnames} """
could not find implicit value for parameter pconv:
scala.slick.jdbc.SetParameter[List[String]]


Is it possible to somehow use
in
clause in
Slick
plain sql queries?

Answer

I don't see anything out of the box to handle this. You're best bet is probably something like this:

val cnames = List("robusta", "arabica").map("'" + _ + "'").mkString(",")
val query = sql""" SELECT c.* FROM Coffees c WHERE c.name IN (${cnames}) """