What are precision and scale for numeric data types in Postgres?
19 Mar 2025, 17:46 UTC
The documentation doesn't have examples.
https://www.postgresql.org/docs/10/datatype-numeric.html#DATATYPE-NUMERIC-TABLE
NUMERIC(precision, scale)
I want to use the smallest amount of space to save a positive number that will be at most 100 and I need to accept decimal increments of 0.5
What precision and scale should I use in this case?
1 answer
Accepted answer · original discussion
22 Mar 2025, 17:46 UTC
Use numeric(4, 1).
This gives you a total of 4 digits maximum (including the decimal part), with 1 digit reserved for the decimals, so this would store numbers up until 999.9.
If you can live with numbers that are not greater than 99.9, then numeric(3, 1) is fine.
Your perspective belongs here.
Sign in with a verified account to contribute.
0 question comments
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.