NUMERIC (arbitrary-precision decimal)
Last updated: 2026-11-04
NUMERIC (arbitrary-precision decimal)
NUMERIC is PostgreSQL's exact decimal type, and DECIMAL is a fully equivalent spelling. It stores decimal digits in a variable-length array and can represent up to 131072 digits before the decimal point and 16383 after it. Because its arithmetic is exact, 0.1 + 0.2 = 0.3 holds strictly. With NUMERIC(p, s), p is the total number of significant digits and s the number of decimal places; excess decimal places are rounded rather than rejected.
| Kind | type |
|---|---|
| Example Language | SQL |
📝 Syntax
NUMERIC | DECIMAL | DEC —— arbitrary precision when unqualified
NUMERIC(precision, scale) —— precision is total significant digits, scale is decimal places
NUMERIC(p) —— equivalent to NUMERIC(p, 0)
Returns:Stores an exact decimal. Without a declared precision it grows as needed; with one, excess decimal places are rounded to the given scale, and an integer part wider than the declared precision raises "numeric field overflow".
▶ Example
Runs real PostgreSQL 18 right in your browser (PGlite WASM, nothing to install). Press ▶ Run and the result appears in the panel below.
Output:
id | price | ratio | col_type | exact_equal
----+---------+------------------------+----------+-------------
1 | 1234.57 | 0.33333333333333333333 | numeric | t
📌 Key Points
- Inserting 1234.567 into numeric(10,2) rounds it to 1234.57; the scale decides how many decimal places survive, and no precision error is raised.
- 1.0/3 yields 0.33333333333333333333 with no floating-point-style tail, while dividing two integers simply gives 0.
- Trade-off: NUMERIC is slower and larger than integers and floats, and it buys absolute reliability for amounts, tax rates and other values that must add up exactly.