How to use OR condition in Slick database queries

I’m working with Slick for database operations and need help with creating OR conditions in my queries. I want to fetch records that match either of two conditions.

Here’s what I’m trying to do:

val CustomerTable = TableQuery[Customer]
CustomerTable.filter(_.status === "active" || _.status.isEmpty)

I need this to generate SQL like:

select * from customer where status = 'active' or status is null

What’s the correct way to write OR conditions in Slick? I tried using || but it doesn’t seem to work as expected. Any help would be appreciated.

The issue arises from using ||, which is suited for boolean expressions rather than Slick’s query conditions. To implement OR logic, you should use a lambda expression for combining filters. The correct syntax is:

val CustomerTable = TableQuery[Customer]
CustomerTable.filter(c => c.status === "active" || c.status.isEmpty)

Alternatively, multiple filter calls could be used, as they are combined with AND, but for OR conditions, stick with the lambda method to ensure it works properly in the database context.

wait, are you getting specific error msgs with the || approach? also, is ur customer table’s status field actually set up as nullable in the schema? sometimes it’s not the query syntax - it’s how the column was defined originally.