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

前端 未结 4 1736
忘掉有多难
忘掉有多难 2021-01-01 14:16

For example, I want to create the following query:

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

My attempt failed:<

4条回答
  •  执念已碎
    2021-01-01 15:03

    Although it's not safe for SQL injection, you can use #$ interpolator:

    val ids = idList.mkString("'", "','", "'")
    val q = sql"""select name from mytable where id in (#$ids)"""
    

提交回复
热议问题