Boolean flags
Define a PostgreSQL table field that stores true/false values.
Drizzle ORM · Function
Drizzle ORM's PostgreSQL boolean() column builder defines a column using PostgreSQL's standard boolean type. It supports chained defaults such as true or the SQL expression sqltrue.
The PostgreSQL boolean column builder creates a column using SQL's standard boolean type. Calling boolean() produces a nullable column by default; chaining default() adds a database default expression, while the inferred TypeScript type remains boolean.
boolean()A PostgreSQL boolean column builder used in a pgTable schema.
true).import { boolean, pgTable } from "drizzle-orm/pg-core";
export const users = pgTable("users", {
isActive: boolean().default(true),
});Defines a PostgreSQL table with a nullable boolean column whose default value is true.
Define a PostgreSQL table field that stores true/false values.
Set a flag automatically when a row is inserted.
Express a database-level boolean default as SQL.
The boolean() builder maps to PostgreSQL's standard boolean type and is imported from drizzle-orm/pg-core. It can be used directly in a pgTable definition.
Follow-up: How would you give the column a default? Chain .default(true), or use .default(sqltrue) when an SQL expression is preferred.
A plain boolean() column is nullable unless you add .notNull(). Adding .default(true) supplies a database default but does not by itself express that every stored value is non-null.
Follow-up: How would you model an always-present enabled flag? Use boolean().notNull().default(true).
The builder can accept a literal default such as true. The documentation also shows an SQL expression form, sqltrue, for the default value.
Follow-up: When would the SQL-expression form be useful? Use it when the default needs to be represented as SQL rather than as a bound literal.
pgTabledefaultsqlnotNullPostgreSQL column types