Search code examples
postgresqlscalaslick

Writing filter for pg-slick for "?|" operator


I'm having trouble writing the query.

Basically I'm querying on jsonb structure and here is how my sql query looks like:

select (p_product -> 'category_id') from product where p_product-> 'category_id' ?| array['3544', '3179'] limit 10;

Here is the scala code I'm trying to use:

  allEvents.filter(row => row.product +> "category_id" ?|.inSetBind(ids.map{_.id}))

This does not work.

On the other hand I'm already able to use the text comparison with something like:

row.product +>> "category_id" inSetBind(ids.map{_.id})

I'm trying to find something online but I'm pretty much out of my own ideas.


Solution

  • I had a look into https://github.com/tminglei/slick-pg/blob/master/addons/spray-json/src/test/scala/com/github/tminglei/slickpg/PgSprayJsonSupportSuite.scala

    So I combined this into:

    allEvents.filter(row => row.product.+>("category_id") ?| ids.map{_.id}.toList.bind)