Define whole-number columns
PostgreSQL schema design
Drizzle ORM · Function
Drizzle ORM's PostgreSQL integer() builder defines a signed 4-byte integer column. Use it in pgTable schemas; choose serial instead when the integer must autoincrement.
In Drizzle's PostgreSQL schema builder, integer() creates a signed four-byte integer column. The resulting column maps to PostgreSQL's integer type; use serial when an auto-incrementing integer is required.
integer()A PostgreSQL integer column builder representing a signed 4-byte integer column.
import { integer, pgTable } from "drizzle-orm/pg-core";
export const users = pgTable("users", {
age: integer(),
});Defines an integer column named age in a PostgreSQL table schema.
PostgreSQL schema design
Schema defaults
Non-autoincrementing identifiers or counters
integer() declares a PostgreSQL signed 4-byte integer column in a Drizzle table definition. It emits the PostgreSQL integer type in the generated schema.
Follow-up: What should be used for an auto-incrementing integer? Use serial, as the documentation directs integer users who need autoincrement to that type.
The function takes no configuration in the documented basic form: integer(). It is used as a column builder inside pgTable.
Follow-up: How would you add a default? Chain .default(10), or provide a SQL expression such as .default(sql10).
integer() is a PostgreSQL-specific column builder imported from drizzle-orm/pg-core. It creates a signed four-byte integer column.
Follow-up: How does the SQLite equivalent differ? SQLite's integer builder supports modes such as number, boolean, timestamp, and timestamp_ms.
serialpgTabledefaultsql