4

I have a raw slick query backed by PostgreSQL. I want to run a query like this: select something from my_table where action in (1,2,3) . Note that action is an integer field in my_table

I'm getting a compilation error in my method below:

could not find implicit value for parameter e: slick.jdbc.SetParameter[List[Int]]

def myMethod(actions: List[Int]]) {
 sql"""select something from my_table 
        where action in (${actions})""".as[MyType]
}

Question

How can I explicitly set the List[Int] parameter so that I can successfully run the in query?

Anthony
  • 33,838
  • 42
  • 169
  • 278

2 Answers2

1

Try

def myMethod(actions: List[Int]) =
  sql"""select something from my_table
        where action in #${actions.mkString("(", ",", ")")}""".as[MyType]

http://slick.lightbend.com/doc/3.3.0/sql.html#splicing-literal-values

https://www.w3schools.com/sql/sql_in.asp

Dmytro Mitin
  • 48,194
  • 3
  • 28
  • 66
1

Use he slick-postgreSQL extensions: https://github.com/tminglei/slick-pg

more info: How to pass an array to a slick SQL plain query?

implicit val setIntArray: SetParameter[Array[Int]] = mkArraySetParameter[Int](...)
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
David Portabella
  • 12,390
  • 27
  • 101
  • 182