postgresql - Can the Postgres data type NUMERIC store signed values? -


in postgresql, store signed values -999.9 - 9999.9. can use numeric(5.1) this?

or type should use?

you can use arbitrary precision type numeric precision of 5 , scale of 1, just @simon commented, without syntax error. use comma(,) instead of dot (.) in type modifier:

select numeric(5,1) '-999.9' nr_lower      , numeric(5,1) '9999.9' nr_upper;   nr_lower | nr_upper ----------+----------    -999.9 |   9999.9 

the minus sign , dot in string literal not count against allowed maximum of significant digits (precision).
if don't need restrict length, use numeric.
if need enforce minimum , maximum, add check constraint:

check (nr_column between -999.9 , 9999.9) 

numeric stores number exactly. if don't need absolute precision , tiny rounding errors no problem, might use 1 of floating point types double precision (float8) or real (float4).

or, since allow single fractional decimal digit, can multiply 10 , use integer, efficient storage: 4 bytes, no rounding errors , fastest processing. use , document number properly.

details numeric types in manual.


Comments

Popular posts from this blog

tcpdump - How to check if server received packet (acknowledged) -