PostgreSQL数字类型,不带零 [英] postgresql numeric type without trailing zeros

查看:370
本文介绍了PostgreSQL数字类型,不带零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用数字类型时,例如这样的 numeric(4,2),并且如果在他体内存储数字 1.2 ,在数字末尾添加零以填充 scale 部分,对吗?结果是 1.20

When use numeric type, for example like this numeric(4,2) and if store in him number 1.2, at end of number are adding zeros for filling scale part right? that is result is 1.20

有可能将空头规模保存为空头吗?

There is possible to save "short" scale as "short"? that is without adding zeros at end ?

推荐答案

您不必担心用于刻度的额外空间部分。

根据文档数字类型值不带尾随零:

According to documentation values of numeric type saved without trailing zeroes:


物理存储数字值没有任何多余的前导或
尾随零。因此,列
的声明精度和小数位数是最大值,而不是固定分配。 (从这种意义上说,数字类型
与varchar(n)相比更类似于char(n)。)实际存储
的要求是每四个十进制数字组两个字节,再加上
三到八个字节的开销。

Numeric values are physically stored without any extra leading or trailing zeroes. Thus, the declared precision and scale of a column are maximums, not fixed allocations. (In this sense the numeric type is more akin to varchar(n) than to char(n).) The actual storage requirement is two bytes for each group of four decimal digits, plus three to eight bytes overhead.

这篇关于PostgreSQL数字类型,不带零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆