0
0
PostgreSQLquery~5 mins

Numeric and decimal precision in PostgreSQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the NUMERIC(p, s) data type represent in PostgreSQL?
It represents a number with p total digits (precision) and s digits after the decimal point (scale).
Click to reveal answer
beginner
What happens if you insert a number with more decimal places than the scale defined in NUMERIC(p, s)?
PostgreSQL rounds the number to fit the defined scale (number of decimal places).
Click to reveal answer
beginner
How does DECIMAL differ from NUMERIC in PostgreSQL?
In PostgreSQL, DECIMAL is just an alias for NUMERIC. Both behave the same way.
Click to reveal answer
intermediate
What is the default precision and scale if you declare a column as NUMERIC without parameters?
It allows any number of digits with no fixed precision or scale, limited only by the system's maximum storage.
Click to reveal answer
intermediate
Why use NUMERIC or DECIMAL instead of FLOAT for money values?
Because NUMERIC stores exact decimal values without rounding errors, which is important for money calculations.
Click to reveal answer
What does the scale in NUMERIC(p, s) specify?
ANumber of digits before the decimal point
BTotal number of digits
CMaximum value allowed
DNumber of digits after the decimal point
If you define a column as NUMERIC(5, 2), what is the largest number you can store?
A999.99
B99999
C9999.9
D99.999
What happens if you insert 12.345 into a NUMERIC(5, 2) column?
AIt stores 12.345 exactly
BIt stores 12.34 without rounding
CIt stores 12.35 after rounding
DIt causes an error
Which data type is best for storing exact monetary values?
AINTEGER
BNUMERIC
CFLOAT
DTEXT
What is the difference between DECIMAL and NUMERIC in PostgreSQL?
ANo difference, they are synonyms
BDECIMAL is faster
CNUMERIC has fixed precision, DECIMAL does not
DDECIMAL stores integers only
Explain how precision and scale work in the NUMERIC(p, s) data type.
Think about total digits and decimal places separately.
You got /4 concepts.
    Why is NUMERIC preferred over FLOAT for financial data?
    Consider the importance of exactness in money.
    You got /4 concepts.