Exact decimal data
Prices, measurements, and financial values requiring exact decimal storage.
Drizzle ORM · Function
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.
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.
numeric(config?)| Name | Type | Description |
|---|---|---|
precision | number | Sets the PostgreSQL numeric precision. |
scale | number | Sets the number of digits after the decimal point. |
mode | 'number' | 'bigint' | Selects the application representation, including number or bigint. |
A PostgreSQL numeric column builder used in a pgTable declaration.
numeric stores exact values and permits configurable precision.mode: 'number' only when the expected values fit safely within JavaScript's number range.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.
Prices, measurements, and financial values requiring exact decimal storage.
Schemas that need a defined maximum precision and fractional scale.
Large exact values that should map to a bigint-oriented application representation.
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.
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.
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.
decimalpgTablecustomType