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

Drizzle ORM · Function

integer

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.

How it works

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.

Syntax

integer()

Returns

A PostgreSQL integer column builder representing a signed 4-byte integer column.

Key points

  • The PostgreSQL integer type stores signed four-byte integer values.
  • PostgreSQL recognizes integer, int, and int4 as names for this type.
  • Import integer and pgTable from drizzle-orm/pg-core for PostgreSQL schemas.
  • Drizzle generates a PostgreSQL CREATE TABLE column using the integer SQL type.

Common mistakes

  • Do not use integer() when you need an auto-incrementing integer; use serial instead.

Example: PostgreSQL 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.

When to use it

Define whole-number columns

PostgreSQL schema design

Add a numeric default to an integer column

Schema defaults

Represent signed 4-byte values

Non-autoincrementing identifiers or counters

Interview questions

QWhat SQL type does Drizzle's PostgreSQL integer() represent?

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.

QHow is integer() used in a PostgreSQL table definition?

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

QWhich package exports the PostgreSQL integer builder?

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.

  • serial
  • pgTable
  • default
  • sql

Source: Drizzle ORM - PostgreSQL column types. Checked 2026-10-16.