Use JavaScript bigint mode
Exact large-integer identifiers or balances
Drizzle ORM · Function
Drizzle’s PostgreSQL bigint builder defines a signed 8-byte integer column. Its mode selects whether application code receives the value as a number, bigint, or string.
Drizzle’s PostgreSQL bigint column builder maps the database’s signed 8-byte integer to a chosen JavaScript representation. Select bigint for exact integer handling, number when values stay within JavaScript’s safe range, or string when preserving the database value as text is preferable.
bigint({ mode: 'number' | 'bigint' | 'string' })| Name | Type | Description |
|---|---|---|
mode | 'number' | 'bigint' | 'string' | Controls the JavaScript type inferred for the column: number, bigint, or string. |
A PostgreSQL bigint column builder, represented in application code according to the selected mode.
import { bigint, pgTable } from "drizzle-orm/pg-core";
export const accounts = pgTable("accounts", {
balance: bigint({ mode: "bigint" }),
displayBalance: bigint({ mode: "number" }),
});Defines PostgreSQL bigint columns with JavaScript bigint and number mappings.
Exact large-integer identifiers or balances
Values above 2^31 but below 2^53
Text-preserving database integrations
The builder creates a PostgreSQL signed 8-byte integer column. Its mode controls the inferred JavaScript type: number, bigint, or string.
Follow-up: How would you preserve exact values beyond JavaScript’s safe integer range? Use mode: 'bigint' or mode: 'string' instead of number.
Use bigint({ mode: 'number' }) when the application expects values above 2^31 but below 2^53. Drizzle then infers the field as number.
Follow-up: What is the risk of exceeding that range? JavaScript number arithmetic may no longer represent every integer exactly.
A PostgreSQL bigint column is not the documented choice for autoincrementing bigint values. The documentation directs users to bigserial for that requirement.
Follow-up: What should be checked when modeling generated identifiers? Choose the serial-family builder matching the database’s generation semantics rather than adding a default manually.
bigserialintintegerint8serial