numeric(m,n)所能插入数值的范围
来源:互联网 发布:天谕 萝莉脸数据 编辑:程序博客网 时间:2024/05/21 11:25
最近看书的时候看到这么一句话:
对于声明了精度的数值,如果insert插入的数值大于声明的精度范围,则会报错。
那么这里的精度范围是什么?精度代表的数值就是位数吗?即3是不是意味着最大值就是999?
测试了一堆数据发现如下:
如果精度和标度都没有声明,那么插入的数值将保持原样,没有范围约束。(当然不可以超出系统内可以实现的精度和标度)。
testdb=# create table numeric(n1numeric(3,0),n2 numeric(3,0),n3 numeric(3,2),n4 numeric);
CREATE TABLE
testdb=# insert into numericvalues(3.1,3.5,3.12,3.123);
INSERT 0 1
testdb=# select * from numeric;
n1 |n2 | n3 | n4
----+----+------+-------
3| 4 | 3.12 | 3.123
(1 row)
可以发现,超出标度的数值确实是按照四舍五入的方式插入的。
testdb=# insert into numeric values(999.4999,5,9.991,13.123);
INSERT 0 1
testdb=# insert into numericvalues(999.5,5,9.994,13.123);
ERROR: numeric field overflow
DETAIL: A field with precision 3, scale 0 must round to an absolute value lessthan 10^3.
STATEMENT: insert into numeric values(999.5,5,9.994,13.123);
ERROR: numeric field overflow
DETAIL: A field with precision 3, scale 0 must round to an absolute value lessthan 10^3.
这两组数据就意味着numeric(3,0)所能插入的最大值为999.4999(9循环),即总是小于999.5。
这个时候我想,那numeric(3,2)是不是就意味着必须小于999.49呢?继续插入数值,找到了临界值:
testdb=# insert into numericvalues(999.4999,5,9.994999999999999999,13.123);
INSERT 0 1
testdb=# insert into numericvalues(1,2,9.995,22.123);
ERROR: numeric field overflow
DETAIL: A field with precision 3, scale 2 must round to an absolute value lessthan 10^1.
STATEMENT: insert into numeric values(1,2,9.995,22.123);
ERROR: numeric field overflow
DETAIL: A field with precision 3, scale 2 must round to an absolute value lessthan 10^1.
这两组数据证明了numeric(3,2)最大值是9.99499999(9循环),即总是小于9.995。这也就是说明所谓的精度范围是要和标度结合的一个范围,精度值表示的位数是要把标度(小数点后几位)算进去的。
而没有精度和标度的数值范围(系统所能承受的精度范围)我并没有测试出来,这个意义不大。
testdb=# insert into numeric
values(999.4999999,999.49999999999,9.99499999999999999,99999999999999.99999999);
INSERT 0 1
testdb=# select * from numeric;
n1 |n2 | n3 | n4
-----+-----+------+-------------------------
3| 4 | 3.12 | 3.123
5| 4 | 3.12 | 3.123
5| 4 | 5.12 | 3.123
13| 4 | 5.12 | 3.123
13| 4 | 8.12 | 13.123
999| 4 | 9.12 | 13.123
999| 5 | 9.99 | 13.123
999| 5 | 9.99 | 13.123
999| 5 | 9.99 | 13.123
999| 5 | 9.99 | 13.123
999| 999 | 9.99 | 99999999999999.99999999
(11 rows)
- numeric(m,n)所能插入数值的范围
- 从N位数字串中删去M个数使剩下的数字串所表示的数值最小
- ruby--数值类(Numeric)
- n! 是否能整除 m 的问题
- 九、 通用工具 ----数值的极限(Numeric Limit)
- 应怎样修改程序 下面的c++程序中deno的数值超出int所能表达的范围 才能得出正确结果
- 有n 个长为m+1 的字符串,求前后m个字符匹配所能形成的最长字符串链:利用弗洛伊德算法求最长路径
- 有n 个长为m+1 的字符串,求前后m个字符匹配所能形成的最长字符串链
- int 整形数所能表示的最大范围
- C/C++中指针所能指向的地址范围
- C++ 整型所能表示的数据范围
- 如何产生m~n范围的随机数 C++
- 类型的数值范围
- (整理)数值范围
- 各类数据的精度、数值范围和在内存中所占的字节数。
- 有 n 个无序整数( n>10000), 则找出其中最大的 M 个数字( 5<M<10), 所需要的最小时间复杂度为:
- Java中任意M~N范围随机数
- 9.5位操作(一)——M插入N,使得M从N的第j位开始,到第i位结束
- Keil使用过程中的常见错误
- 用免安装版apache-jmeter-2.12和HttpWatch Professional 写性能测试脚本
- 高效能人士的7个习惯
- Class类 是啥java
- 前端性能优化的14条法则
- numeric(m,n)所能插入数值的范围
- 求俩个时间内的所有月份
- 重装VS2015中的HlpViewer.exe
- 关于应用logo在小米手机上不显示新logo解决方式
- 九个步骤让你成为PHP专家
- How to remove error about glyphicons-halflings-regular.woff2 not found
- State Estimation for Robotics_2.1.5_Statistically Independent, Uncorrelated
- JAVA创建和销毁对象
- find 一个小例子