Slick - Filter Row if Column is Null

BAR picture BAR · Feb 4, 2015 · Viewed 9.9k times · Source

How do I filter rows in Slick if a column is null?

val employees = Queryable[Employees]

// Error
val query = employees.filter( _.terminationDate == Nil )

Might be important to note that

terminationDate: Option[String]

I am using Direct Embedding.

Answer

Ende Neu picture Ende Neu · Feb 4, 2015

Slick has its own why of checking for null values in a column:

val query = employees.filter(_.terminationDate.isNull)

The opposite is isNotNull.

Or in newer versions of Slick:

val query = employees.filter(_.terminationDate.isEmpty)

and

val query = employees.filter(_.terminationDate.isDefined)