Find missing values
Retrieve records with an unset optional field.
Drizzle ORM · Function
isNull creates a Drizzle filter for rows where a column or SQL expression is SQL NULL. Use it inside a query's where clause to generate an IS NULL predicate.
isNull builds a filter that matches rows where the supplied column or SQL expression has the SQL NULL value. Pass the resulting condition to a query builder's where method to generate an IS NULL predicate.
isNull(column)| Name | Type | Description |
|---|---|---|
column | Column or SQL expression | Column or SQL expression whose value should be tested for SQL NULL. |
A SQL filter condition representing an IS NULL predicate.
import { drizzle } from "drizzle-orm/node-postgres";
import { isNull } from "drizzle-orm";
import { users } from "./schema";
const db = drizzle(process.env.DATABASE_URL!);
const rows = await db.select().from(users).where(isNull(users.deletedAt));
console.log(rows);Selects users whose deletedAt column contains SQL NULL.
Retrieve records with an unset optional field.
Select records not yet marked as deleted.
Restrict a query to rows lacking a nullable relationship key.
isNull is imported from drizzle-orm and accepts a column or SQL expression. Used in where, it produces an IS NULL condition for matching rows.
Follow-up: How would you match non-null values? Use the corresponding isNotNull operator in the same filter-operator family.
Call isNull with the target column, then pass the returned condition to where, such as where(isNull(table.column)). The documented SQL shape is a SELECT with table.column IS NULL.
Follow-up: How can this condition be combined with another predicate? Compose it with Drizzle's logical filter operators, such as and or or.
The function represents a SQL NULL comparison rather than an ordinary equality comparison. Its documented purpose is to filter rows whose value is null.
Follow-up: Why not use eq(column, null)? Use the dedicated null predicate so the generated SQL uses IS NULL semantics.
isNotNullandoreq