Rails PostgreSQL数字字段溢出错误 [英] Rails PostgreSQL numeric field overflow ERROR
问题描述
我有一个十进制字段的价格在我的架构和每次,我试图插入价格的pg与这个错误。任何人都可以给我任何光?感谢
I have a decimal field for price on my schema and every time that i try to insert the price the pg comes with this ERROR. anybody could give me any light? thank's
配置
t.decimal "price", :precision => 2, :scale => 2
ERROR
PG::Error: ERROR: numeric field overflow
DETAIL: A field with precision 2, scale 2 must round to an absolute value less than 1.
: INSERT INTO "items" ("category_id", "name", "price", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14) RETURNING "id"
推荐答案
任意精确数字: p>
I quote the manual on Arbitrary Precision Numbers:
数字的刻度是小数点右边的
小数部分中的小数位数。
数字的精度是整数中有效数字的总计数,
,即小数点两边的数字数。
The scale of a numeric is the count of decimal digits in the fractional part, to the right of the decimal point. 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.
您不能将数字> = 1
分配到数据类型 numeric ,2)
。
You cannot assign numbers >= 1
to a column of the data type numeric(2,2)
. There is just no room for digits before the decimal point.
0.999
和 0.995
也违反了类型,因为它们以给定的缩放 2 <转换为 1
/ em>。
0.999
and 0.995
are in violation of the type as well, as they round to 1
with a given scale of 2.
这篇关于Rails PostgreSQL数字字段溢出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!