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
✗ Incorrect
The scale s specifies how many digits appear 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
✗ Incorrect
With precision 5 and scale 2, you have 3 digits before and 2 digits after the decimal point, so max is 999.99.
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
✗ Incorrect
The value is rounded to 2 decimal places, so 12.345 becomes 12.35.
Which data type is best for storing exact monetary values?
AINTEGER
BNUMERIC
CFLOAT
DTEXT
✗ Incorrect
NUMERIC stores exact decimal values, avoiding rounding errors common with FLOAT.
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
✗ Incorrect
In PostgreSQL, DECIMAL and NUMERIC are the same data type.
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.
Practice
(1/5)
1. What does the scale represent in a NUMERIC(10, 3) data type in PostgreSQL?
easy
A. The number of digits after the decimal point
B. The total number of digits allowed
C. The number of digits before the decimal point
D. The maximum value allowed
Solution
Step 1: Understand NUMERIC precision and scale
In NUMERIC(precision, scale), precision is total digits, scale is digits after decimal.
Step 2: Apply to NUMERIC(10, 3)
Here, scale = 3 means 3 digits after decimal point.
Final Answer:
The number of digits after the decimal point -> Option A
Quick Check:
Scale = digits after decimal [OK]
Hint: Scale is digits after decimal point in NUMERIC [OK]
Common Mistakes:
Confusing scale with precision
Thinking scale is digits before decimal
Assuming scale limits total digits
2. Which of the following is the correct syntax to define a column named price with 7 digits total and 2 digits after the decimal in PostgreSQL?
easy
A. price DECIMAL(7)
B. price NUMERIC(2,7)
C. price DECIMAL(2,7)
D. price NUMERIC(7,2)
Solution
Step 1: Recall NUMERIC/DECIMAL syntax
Syntax is NUMERIC(precision, scale) where precision >= scale.
Step 2: Match precision=7 and scale=2
price NUMERIC(7,2) uses NUMERIC(7,2) which means 7 total digits, 2 after decimal.
Final Answer:
price NUMERIC(7,2) -> Option D
Quick Check:
NUMERIC(precision, scale) = NUMERIC(7,2) [OK]
Hint: Precision first, scale second in NUMERIC/DECIMAL [OK]
Common Mistakes:
Swapping precision and scale
Using scale larger than precision
Omitting scale when needed
3. Given the table products(price NUMERIC(5,2)), what will be the stored value after inserting INSERT INTO products(price) VALUES (123.4567);?
medium
A. 123.45
B. 123.46
C. 123.4567
D. Error: value too precise
Solution
Step 1: Understand NUMERIC(5,2) limits
Precision 5 means total 5 digits, scale 2 means 2 digits after decimal.
Step 2: Round input 123.4567 to 2 decimal places
123.4567 rounds to 123.46 to fit scale 2.
Final Answer:
123.46 -> Option B
Quick Check:
Rounded to 2 decimals = 123.46 [OK]
Hint: NUMERIC rounds to scale digits on insert [OK]
Common Mistakes:
Expecting truncation instead of rounding
Assuming error on extra decimals
Ignoring precision limits
4. You defined a column as amount NUMERIC(4,2). You try to insert 999.99 but get an error. What is the problem?
medium
A. NUMERIC cannot store decimal values
B. The scale 2 is too small for the value
C. The value exceeds the total precision of 4 digits
D. Syntax error in column definition
Solution
Step 1: Calculate digits in 999.99
999.99 has 5 digits total (3 before decimal + 2 after).
Step 2: Compare with NUMERIC(4,2)
NUMERIC(4,2) allows only 4 digits total, so 999.99 is too large.
Final Answer:
The value exceeds the total precision of 4 digits -> Option C
Quick Check:
Value digits > precision causes error [OK]
Hint: Total digits must fit precision, not just decimals [OK]
Common Mistakes:
Thinking scale limits integer part
Believing NUMERIC disallows decimals
Ignoring precision limits
5. You want to store monetary values up to 999999.999 with exact precision in PostgreSQL. Which column definition is best to avoid rounding errors and allow this range?
hard
A. amount NUMERIC(9,3)
B. amount NUMERIC(6,3)
C. amount DECIMAL(9,2)
D. amount FLOAT(9)
Solution
Step 1: Determine needed precision and scale
Value 999999.999 has 6 digits before decimal, 3 after, total 9 digits.
Step 2: Choose NUMERIC with precision 9 and scale 3
NUMERIC(9,3) stores exactly 9 digits total with 3 decimals, matching requirement.
Step 3: Avoid FLOAT for exact money values
FLOAT is approximate, may cause rounding errors.
Final Answer:
amount NUMERIC(9,3) -> Option A
Quick Check:
Exact money storage needs NUMERIC(9,3) [OK]
Hint: Use NUMERIC with precision = digits total, scale = decimals [OK]
Common Mistakes:
Using FLOAT for money causing rounding errors
Choosing too small precision or scale
Confusing DECIMAL scale with precision
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.