Sameerel
Sameerel

Reputation: 121

Slick compare table column with null

Can someone please tell me how do we compare a table column against NULL using slick's lifted embedding.

What i want to achieve in mysql:

select * from Users where email = '<some_email_addr>' and ( removed = NULL OR removed <= 1 )

It gives me an errors at x.removed === null when i try:

val q = for {
    x <- Users
        if x.email === email && ( x.removed === null || x.removed <= 1 )
} yield x.removed

Thanks

Upvotes: 7

Views: 6442

Answers (3)

Mar77i
Mar77i

Reputation: 71

As daaatz said and per http://slick.typesafe.com/doc/2.1.0/upgrade.html#isnull-and-isnotnull you should use isEmpty, but it only works on Option columns. A workaround is x.removed.?.isEmpty.

Upvotes: 7

cmbaxter
cmbaxter

Reputation: 35443

Try:

x.removed.isNull

I think that is what you are looking for

Upvotes: 16

daaatz
daaatz

Reputation: 394

Try

x.removed.isEmpty()

There are no nulls in scala ;-)

Upvotes: 4

Related Questions