gpt4 book ai didi

sql - PostgreSQL:十进制/数字数据类型的数字字段溢出 - 为什么会出现此错误

转载 作者:行者123 更新时间:2023-12-04 02:25:12 59 4
gpt4 key购买 nike

我创建了一个这样的表

CREATE TABLE foo (
id serial CONSTRAINT id_pk PRIMARY KEY,
bar varchar(256),
test decimal(5,5)
);

然后我想填充 test

 INSERT INTO foo (test) VALUES (12345.12345)

这给了我

Numeric field overflowDetail: A field with precision 5, scale 5must round to an absolute value less than 1.

我不明白这个。不过,如果我将一列设置为 decimal(5,5),我必须在逗号左侧有五个数字,在逗号右侧有五个数字。我有号码 12345.12345

为什么会给我这个错误?

最佳答案

您误解了指定小数的工作原理(我同意这有点令人困惑)。

Quote from the manual

The precision of a numeric is the total count of significant digits in the whole number, that is, the number of digits to both sides of the decimal point. The scale of a numeric is the count of decimal digits in the fractional part, to the right of the decimal point

所以第一个数字定义了位数,第二个定义了小数位数。

如果你想要小数点前5位和小数点后5位,你需要使用decimal(10,5)

关于sql - PostgreSQL:十进制/数字数据类型的数字字段溢出 - 为什么会出现此错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68312588/

59 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com