2

I am storing a running total in a Decimal(10,2) field and adding to it as items are processed.

update foo set bar = bar + '3.15'

About 20% of the times a warning is issued "Data truncated for column 'bar' at row 4"

This warning is never issued if the update value is not quoted. Should decimal values be quoted?

4

5 回答 5

4

当然不是。

整数和浮点数不是字符串,不应该被引用。只有 MySQL 甚至允许在它们周围加上引号。

于 2010-04-01T08:45:35.087 回答
2

您添加的值是否可能超过 的限制Decimal(10,2)

例如

update foo set bar = bar + '3.149999'

会导致“数据被截断”警告,因为该字段只能存储小数点右侧的 2 位数字(不是 6 位)。

于 2010-04-01T08:54:52.473 回答
1

不,十进制值按原样指定。如果您引用它们,它将解释为 varchar。

于 2010-04-01T08:45:42.777 回答
0

不!引号仅用于字符串,例如 text、char、varchar 等

于 2010-04-01T08:57:45.337 回答
0

如果您不引用 NUMERIC/DECIMAL 值,它们可能会首先转换为 FLOAT(失去精度),然后转换为您想要的类型。您还可以使用 CAST 关键字 (MySQL) 或 :: cast (Postgres)。

于 2010-04-01T12:15:47.867 回答