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

Drizzle ORM · Function

numeric

Drizzle's PostgreSQL numeric builder defines exact numeric columns with optional precision, scale, and application modes. It supports JavaScript number or bigint representations when appropriate.

How it works

The PostgreSQL numeric column builder represents exact numeric data. You can optionally set precision and scale, or choose a number or bigint application mode while retaining PostgreSQL's numeric SQL type.

Syntax

numeric(config?)

Parameters

NameTypeDescription
precisionnumberSets the PostgreSQL numeric precision.
scalenumberSets the number of digits after the decimal point.
mode'number' | 'bigint'Selects the application representation, including number or bigint.

Returns

A PostgreSQL numeric column builder used in a pgTable declaration.

Key points

  • PostgreSQL numeric stores exact values and permits configurable precision.
  • A precision option can be supplied without specifying scale.
  • Precision and scale can be configured together for fixed decimal layouts.
  • The builder can expose the column through a JavaScript number mode.
  • The builder also documents a bigint application mode for numeric columns.

Common mistakes

  • PostgreSQL numeric supports values far beyond JavaScript's ordinary numeric range; choose an application mode deliberately when handling large values.
  • Use mode: 'number' only when the expected values fit safely within JavaScript's number range.

Example: PostgreSQL numeric columns

import { numeric, pgTable } from "drizzle-orm/pg-core";

export const products = pgTable("products", {
  price: numeric({ precision: 10, scale: 2 }),
  exactPrice: numeric({ mode: "number" }),
});

Defines PostgreSQL exact-numeric columns, including a precision/scale-constrained value and a column mapped to a JavaScript number.

When to use it

Exact decimal data

Prices, measurements, and financial values requiring exact decimal storage.

Constrained precision

Schemas that need a defined maximum precision and fractional scale.

Large numeric values

Large exact values that should map to a bigint-oriented application representation.

Interview questions

QWhat does Drizzle's PostgreSQL numeric builder represent?

numeric() declares an exact PostgreSQL numeric column. Passing precision and scale produces a constrained declaration such as numeric(100, 20).

Follow-up: How can the application representation be changed? Pass mode: 'number' or mode: 'bigint' to select the corresponding Drizzle type while keeping the database type numeric.

QHow are precision and scale configured?

Precision controls the declared precision, while scale controls the digits after the decimal point. For example, numeric({ precision: 100, scale: 20 }) maps to numeric(100, 20).

Follow-up: What SQL does an unconstrained builder generate? numeric() generates a PostgreSQL numeric column without precision and scale arguments.

QWhich application modes are available?

The builder supports mode: 'number' and mode: 'bigint' in addition to the default representation shown by the documentation. These modes let the application choose how selected and inserted values are typed.

Follow-up: Why should mode selection consider the value range? JavaScript number safety limits make number unsuitable for arbitrarily large exact values.

  • decimal
  • pgTable
  • customType

Source: timestamp | Drizzle ORM. Checked 2026-10-16.