PostgreSQL学习篇9.2 数值类型
发布时间:2020-12-13 16:59:43 所属栏目:百科 来源:网络整理
导读:数值类型解释 PostgreSQL中的所有数值类型及其解释: 类型名称 存储空间 描述 smallint 2字节 小范围整数。Oracle中没有此类型,使用number代替 int或integer 4字节 常用的整数。Oracle中的integer等效于number(38),与此类型的意义不同 bigint 8字节 大范围
数值类型解释
PostgreSQL中的所有数值类型及其解释:
整数类型 整数类型有三种:smallint、int、bigint int、integer、int4等效;int2、smallint等效;bigint、int8等效。 精确的小数类型 精确的小树类型可用numeric、numeric(m,n)、numeric(m)表示。 numeric与decimal等效,可以存储最多1000位精度的数字,并且可以进行准确的计算。适合货币金额和其他要求精确计算的场合。不过,numeric类型上的算术运算比证书类型或浮点数类型慢很多(类似于Oracle里面的number,但是,Oracle中int相当于number(m,0))。 示例: postgres=# create table test(col1 numeric(3),col2 numeric(3,0),col3 numeric(3,2),col4 numeric); CREATE TABLE postgres=# postgres=# insert into test values (2,2,2.222,2.222); INSERT 0 1 postgres=# select * from test; col1 | col2 | col3 | col4 ------+------+------+------- 2 | 2 | 2.22 | 2.222 (1 row) postgres=# insert into test values(22,22,22.222,22.222); ERROR: numeric field overflow DETAIL: A field with precision 3,scale 2 must round to an absolute value less than 10^1. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |