ps0604 ps0604 - 2 months ago 17
Scala Question

Where condition in Slick

How to achieve the equivalent in Slick?

select * from table1 where col1 = 1 AND (col2 = 2 or col3 = 3)


This doesn't work:

val action = table.filter(_.col1 === 1 && (_.col2 === 2 || _.col3 === 3)).result

Answer

You cannot use the short hand in this case. Try this:

 val action = table.filter( x => x.col1 == 1 && (x.col2 == 2 || x.col3 == 3)).result