关于postgresql中numeric和decimal的精度和标度问题

精度即数的有效数字个数

2.5的有效数字个数是2,但是053.2的有效数字个数是3

标度是小数点的位数

例如numeric(2,1),即这个数必须是两位,并且小数后面最多有一位,多出来的小数会被四舍五入

可以很容易的确定出numeric的范围,即-10(精度-标度)到10(精度-标度)次方之间,不包括两头

create table test (num numeric(2,1));
insert into test values (2.2);
 num 
-----
 2.2
insert into test values (2.26);
 num 
-----
 2.3
insert into test values (10);
ERROR:  numeric field overflow
DETAIL:  A field with precision 2, scale 1 must round to an absolute value less than 10^1.
原文地址:https://www.cnblogs.com/monkey6/p/12421181.html