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

后端 未结 3 1415
迷失自我
迷失自我 2021-01-05 01:03

There is a similar question here but it doesn\'t actually answer the question.

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

Note that this is actually

3条回答
  •  一生所求
    2021-01-05 01:49

    Although this is not universal answer and may not be what the author wanted, I still want to point this out to whoever views this question.

    Some DB backends support array types, and there are extensions to Slick that allow setting these array types in the interpolations.

    For example, Postgres has the syntax where column = any(array), and with slick-pg you can use this syntax like so:

    def query(ids: Seq[Long]) = db.run(sql"select * from table where ids = any($ids)".as[Long])
    

    This brings a much cleaner syntax, which is friendlier to the statement compiler cache and also safe from SQL injections and overall danger of creating a malformed SQL with the #$var interpolation syntax.

提交回复
热议问题