Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Drizzle ORM · Function

boolean

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.

How it works

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.

Syntax

boolean()

Returns

A PostgreSQL boolean column builder used in a pgTable schema.

Key points

  • PostgreSQL's boolean() builder represents the database's standard SQL boolean type.
  • Import boolean and pgTable from drizzle-orm/pg-core when defining PostgreSQL schemas.
  • Chain default(true) to define a true default for the boolean column.
  • An SQL true expression can also be supplied through default(sqltrue).

Example: Define a PostgreSQL boolean column

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.

When to use it

Boolean flags

Define a PostgreSQL table field that stores true/false values.

Default-enabled records

Set a flag automatically when a row is inserted.

SQL defaults

Express a database-level boolean default as SQL.

Interview questions

QWhat does boolean() represent in a PostgreSQL Drizzle schema?

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.

QIs a boolean column non-nullable by default?

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).

QHow can boolean defaults be declared?

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.

  • pgTable
  • default
  • sql
  • notNull
  • PostgreSQL column types

Source: timestamp. Checked 2026-10-16.