I am trying to construct a Slick query with a negated inSet
but I am having trouble figuring out the correct syntax. I'd like to do something like
val lst = List(1, 2, 3)
Query(Table1).where(_.id1 === 1).where(!(_.id2 inSet lst)).list
or
Query(Table1).where(_.id1 === 1).where(isNot(_.id2 inSet lst)).list
neither of which passes muster. Is it possible to negate an inSet
like this, and if so what is the correct syntax? Or is there another way to construct the query that wouldn't require the negated inSet
? I'm using Slick 1.0.1, I expect that we'll be upgrading to Slick 2.0 within the next month. (I can apply a filterNot(lst.contains(_.id2))
to the query results instead of putting a negated inSet
inside of the query, but this would complicate the function I'm writing and so I'd rather use a negated inSet
if possible.)
One of
Query(Table1).filter(_.id1 === 1).filter(row => !(row.id2 inSet lst)).list
Query(Table1).filter(_.id1 === 1).filterNot(_.id2 inSet lst).list
Related: https://github.com/slick/slick/pull/204
Side notes: where
is deprecated. Use Scala collections terminology instead of SQL terminology. Also, you are under the wrong assumption that in Scala !(_.id2 inSet lst)
expands to x => !(x.id2 inSet lst)
when in fact it expands to !(x => x.id2 inSet lst)
which does not make much sense.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With