liveBook · Manning

Decimal

As explained in PostgreSQL Mistakes and How to Avoid Them

NUMERIC is an exact SQL numeric data type for storing values with specified precision and scale.

Decimal, also called NUMERIC in PostgreSQL, stores exact numeric values with specified precision and scale. NUMERIC and DECIMAL are equivalent names in PostgreSQL. section 3.6

Use NUMERIC for monetary amounts instead of MONEY or floating-point types. MONEY does not record its currency and accepts malformed input, while real and double precision can introduce rounding errors. Store the currency in a separate adjacent column. section 3.6 section 3.9

Avoiding numeric type mismatches

During a migration, do not map another database's NUMBER type by name alone. Oracle NUMBER can represent integers and floating-point values, whereas PostgreSQL distinguishes numeric, integer, and floating-point types. Check each definition and use PostgreSQL conversion functions or migration tools to preserve precision and calculations. section 10.5

How PostgreSQL Mistakes and How to Avoid Them covers it

How deep it goes
Defines NUMERIC and DECIMAL equivalence, explains monetary trade-offs, and warns against cross-database type-name assumptions.
Examples
Contrasts NUMERIC with MONEY and floating-point types, then uses Oracle NUMBER migration as a compatibility example.
What it assumes
Assumes familiarity with SQL data types and migration, while clarifying PostgreSQL's distinction between numeric, integer, and floating-point values.
What you can do after
Evaluate numeric choices, select NUMERIC for exact amounts, separate currency, and diagnose migration mappings that risk precision loss.
How it connects
Connects exact numeric storage with MONEY, floating-point types, currency columns, type conversion, and database migration.

Also explained in

Compare how 5 books explain Decimal →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of PostgreSQL Mistakes and How to Avoid Them. The section links point to the parts of the book it draws on.