NUMERIC

Learn how to use the PostgreSQL NUMERIC type for exact decimal storage, including precision and scale, rounding behavior, NaN handling, and when to prefer it over FLOAT.

5 min read · Last updated: March 2026 · Back to overview

Quick Answer

The PostgreSQL NUMERIC(precision, scale) type stores exact decimal numbers with up to 131,072 digits before the decimal point and 16,383 after. Use it for monetary amounts and any value requiring exact arithmetic instead of floating-point approximations.

Spin up a Postgres database in 20 seconds with Vela.

Try Vela Sandbox

The PostgreSQL NUMERIC type (also called DECIMAL) stores numbers with exact precision. It is the correct choice for financial data, quantities, or any value where floating-point approximation is unacceptable.

Syntax and precision/scale

column_name NUMERIC(precision, scale)
  • precision: total number of significant digits
  • scale: digits to the right of the decimal point

Example: NUMERIC(7, 2) stores up to 99999.99. If you omit both, NUMERIC defaults to up to 131,072 digits before and 16,383 after the decimal point.

NUMERIC, DECIMAL, and DEC are all synonyms:

price NUMERIC(5,2)
price DECIMAL(5,2)
price DEC(5,2)  -- all equivalent

Rounding and overflow behavior

CREATE TABLE products (
  id    SERIAL PRIMARY KEY,
  name  VARCHAR(100) NOT NULL,
  price NUMERIC(5,2)
);

Inserting values with more decimal places than the scale causes automatic rounding:

INSERT INTO products (name, price)
VALUES ('Phone', 500.215), ('Tablet', 500.214);

SELECT * FROM products;
id |  name  | price
----+--------+--------
 1 | Phone  | 500.22
 2 | Tablet | 500.21

Exceeding the total precision raises an error:

INSERT INTO products (name, price) VALUES ('Phone', 123456.21);
-- ERROR: numeric field overflow
-- DETAIL: A field with precision 5, scale 2 must round to an absolute value less than 10^3.

NaN: not-a-number

NUMERIC supports the special value NaN (not-a-number). It must be quoted when used as a literal:

UPDATE products SET price = 'NaN' WHERE id = 1;

SELECT * FROM products ORDER BY price DESC;
id |  name  | price
----+--------+--------
 1 | Phone  |    NaN
 2 | Tablet | 500.21

In PostgreSQL, NaN is considered greater than all regular numbers and equal to itself — unlike IEEE 754 — so it sorts predictably and works in indexes.

Production tips

  • Always use NUMERIC for monetary values — never FLOAT or DOUBLE PRECISION, which can introduce rounding errors in financial calculations.
  • Arithmetic on NUMERIC is slower than on integer or float types. For non-financial data where approximation is acceptable, prefer DOUBLE PRECISION.
  • Use NUMERIC(p, s) with explicit precision and scale for columns that interface with external systems to prevent unexpected precision changes.
  • To store currency, a common pattern is NUMERIC(19, 4) — 15 digits before the decimal and 4 after, providing enough room for most real-world monetary values.

Reference: PostgreSQL documentation — Numeric Types.

Continue in PostgreSQL Data Types: DOUBLE PRECISION.

Related in this section: Boolean · CHAR, VARCHAR, and TEXT · DOUBLE PRECISION

Frequently Asked Questions

What is the difference between NUMERIC and FLOAT in PostgreSQL?

NUMERIC stores exact decimal values and is suitable for monetary amounts and precise calculations. FLOAT (double precision) stores approximate values using IEEE 754 floating-point, which can produce rounding errors (e.g., 0.1 + 0.1 + 0.1 may not equal 0.3 exactly). Use NUMERIC when exactness is required; use FLOAT when performance matters more than precision.

What do precision and scale mean in NUMERIC(p, s)?

Precision (p) is the total number of significant digits across both sides of the decimal point. Scale (s) is the number of digits to the right of the decimal point. For example, NUMERIC(7, 2) can store values up to 99999.99. If you insert a value with more fractional digits than the scale, PostgreSQL rounds it to fit.

Is DECIMAL the same as NUMERIC in PostgreSQL?

Yes. DECIMAL and NUMERIC are synonyms in PostgreSQL. DEC is also accepted. All three types behave identically and can be used interchangeably in column definitions.

What happens if I insert a value that exceeds the NUMERIC precision?

PostgreSQL raises an error: "numeric field overflow". For example, inserting 123456.21 into a NUMERIC(5,2) column fails because the value requires 8 significant digits but the column allows only 5. Values that only exceed the scale (too many decimal places) are rounded, not rejected.

What is NaN in the context of PostgreSQL NUMERIC?

NaN stands for "not-a-number" and is a special NUMERIC value used to represent undefined results. Unlike IEEE 754 where NaN != NaN, PostgreSQL treats NaN values as equal and greater than all regular numbers, which allows sorting and indexing to work correctly on NUMERIC columns containing NaN.