Question 1
Topic: PostgreSQL Fundamentals
Skill tested: Select PostgreSQL data types that preserve exact decimal values and support reliable arithmetic.
A billing service stores unit prices and tax rates that must remain exact when reports calculate totals. The application currently uses a floating-point column, and repeated calculations produce small rounding differences. The schema must support fixed decimal precision, and the developers want the database to reject values that exceed the intended scale rather than silently rely on binary floating-point representation. Which data type is the best fit for the monetary values?
NUMERIC (also called DECIMAL) stores decimal values with user-defined precision and scale, making it appropriate when exact decimal arithmetic is required. Specifying both lets the schema enforce the intended range and fractional scale. REAL and DOUBLE PRECISION use binary floating-point, so many decimal fractions cannot be represented exactly; a display-oriented check does not change that. INTEGER can work only with a carefully defined scaled-integer convention, but it does not directly represent the requested decimal values and requires conversion logic.