Keep rows with a populated nullable column
Nullable database fields
Drizzle ORM · Function
isNotNull creates a Drizzle filter that keeps rows whose value is not SQL NULL. Use it in where() to generate an IS NOT NULL predicate.
isNotNull builds a SQL predicate that tests whether a column or SQL expression is not NULL. Pass it to where() to retain only rows satisfying the IS NOT NULL condition.
isNotNull(column)A SQL filter expression representing an IS NOT NULL condition.
import { isNotNull } from "drizzle-orm";
import { users } from "./schema";
const rows = await db
.select()
.from(users)
.where(isNotNull(users.email));Selects users whose email column is not SQL NULL.
Nullable database fields
Query filtering
isNotNull creates a filter for values that are not SQL NULL. Used in where(), it generates an IS NOT NULL predicate for the selected column.
Follow-up: What SQL does it represent? It represents a condition such as "column" IS NOT NULL, as shown by the operator documentation.
Import isNotNull from drizzle-orm, then pass the target table column to it inside a query's where() clause. The result is a type-safe Drizzle filter expression.
Follow-up: How would you combine it with another condition? Use Drizzle's documented filter-composition operators, such as and(), around the individual predicates.
The predicate excludes rows where the tested value is NULL and keeps rows where it is not NULL. Drizzle translates that predicate into SQL rather than requiring a handwritten SQL fragment.
Follow-up: How does the generated SQL express the test? It uses the SQL IS NOT NULL operator on the referenced column.
isNullandor