// data type reference

NUMERIC and DECIMAL

Exact fixed-point decimals: NUMERIC(p,s) and DECIMAL(p,s).

Missing in
None of the five
Gotchas
4 listed

Engine by engine

SQL Server, PostgreSQL, MySQL and Oracle all have true exact decimals; SQLite's NUMERIC affinity silently degrades to floats.

NUMERIC / DECIMAL in SQL Server, PostgreSQL, MySQL, SQLite and Oracle: type name, storage and notes
Engine Typ Speicher Notizen
SQL Server DECIMAL(p,s) / NUMERIC 5-17 bytes Exact synonyms; precision 1-38. Storage is 5 bytes up to p=9, 9 to p=19, 13 to p=28, 17 to p=38.
PostgreSQL NUMERIC(p,s) / DECIMAL(p,s) 2 bytes per 4 digits + 3-8 bytes Declared precision up to 1,000; unconstrained NUMERIC holds up to 131,072 digits before and 16,383 after the point.
MySQL DECIMAL(p,s) variable, ~4 bytes per 9 digits NUMERIC is a synonym; precision up to 65, scale up to 30.
SQLite NUMERIC (affinity) variable (INTEGER or REAL) No true decimal: NUMERIC affinity stores values as INTEGER or IEEE REAL, so 0.1 drifts.
Oracle NUMBER(p,s) variable, 1-21 bytes NUMBER covers integers and decimals alike; precision 1-38.

Gotchas

Where the engines disagree. These tend to surface as bugs during a migration or a port.

  1. SQLite has no exact decimal: a NUMERIC column keeps 0.1 as an 8-byte float. Store cents as INTEGER or use a decimal extension.
  2. NUMERIC and DECIMAL are exact synonyms in SQL Server, PostgreSQL and MySQL alike; the type underneath differs per engine, the guarantee does not.
  3. Extra fractional digits are rounded, not rejected, in all four exact engines: 1.005 into DECIMAL(4,2) or NUMBER(4,2) stores 1.01. Only too many integer digits raise an error.
  4. MySQL clamps out-of-range DECIMAL values to the endpoint with a warning unless strict mode (the default since 5.7) is on.

Common questions

Are NUMERIC and DECIMAL different?

No, in every engine covered here they are synonyms for the same exact type. The standard distinguishes their required precision; no implementation does.

How do I store money exactly in SQLite?

Store integer cents in an INTEGER column, or load a decimal extension. NUMERIC affinity will not protect you from binary float drift.

What does NUMERIC(p,s) mean?

p is the total number of significant digits, s how many sit right of the decimal point. NUMERIC(6,2) holds up to 9,999.99.

// map types before you move data

Map a type to the other four engines

The free type converter maps a type from one engine to its closest equivalent in the others and says where storage, precision or behaviour differ. The desktop app does the same mapping while you edit.