NUMERIC and DECIMAL
Exact fixed-point decimals: NUMERIC(p,s) and DECIMAL(p,s).
- Family
- Exact decimals
- 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.
| 엔진 | 타입 | 저장소 | 메모 |
|---|---|---|---|
| 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.
- 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.
- NUMERIC and DECIMAL are exact synonyms in SQL Server, PostgreSQL and MySQL alike; the type underneath differs per engine, the guarantee does not.
- 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.
- 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.
Related on SQLly
- SQL data type comparison and converter Free tool
- Cast text to a number in SQL Server, PostgreSQL, MySQL, SQLite and Oracle Dialect comparison
- Cast syntax in SQL Server, PostgreSQL, MySQL, SQLite and Oracle Dialect comparison
- Integer and decimal division in SQL Server, PostgreSQL, MySQL, SQLite and Oracle Dialect comparison
- SQL CAST to DECIMAL 함수
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.