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

Drizzle ORM · Function

bigint

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.

How it works

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.

Syntax

bigint({ mode: 'number' | 'bigint' | 'string' })

Parameters

NameTypeDescription
mode'number' | 'bigint' | 'string'Controls the JavaScript type inferred for the column: number, bigint, or string.

Returns

A PostgreSQL bigint column builder, represented in application code according to the selected mode.

Key points

  • The column stores signed 8-byte integer values.
  • The number mode makes the declared field infer as a JavaScript number.
  • The bigint mode makes the declared field infer as a JavaScript bigint.
  • The string mode makes the declared field infer as a JavaScript string.
  • A bigint column can receive a numeric SQL expression as its default.

Common mistakes

  • Use bigserial rather than bigint when the column must be an autoincrementing PostgreSQL value.
  • The number mode is appropriate only when values remain within JavaScript’s safely representable range; larger integers can lose precision.

Example: Define bigint columns

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.

When to use it

Use JavaScript bigint mode

Exact large-integer identifiers or balances

Use number mode

Values above 2^31 but below 2^53

Use string mode

Text-preserving database integrations

Interview questions

QWhat does Drizzle’s PostgreSQL bigint builder represent, and how does mode affect it?

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.

QWhen is mode: 'number' suitable?

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.

QShould bigint be used for an autoincrementing PostgreSQL column?

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.

  • bigserial
  • int
  • integer
  • int8
  • serial

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