scalaslickslick-2.0

Slick - Filter Row if Column is Null


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.


Solution

  • Newer versions of Slick:

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

    and

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

    Older versions of Slick had their own way of checking for null values in a column:

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

    The opposite was isNotNull.