Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 更改数字列以降低精度_Sql_Postgresql - Fatal编程技术网

Sql 更改数字列以降低精度

Sql 更改数字列以降低精度,sql,postgresql,Sql,Postgresql,我在postgres数据库模式的表中有一个数字列,它的精度为n 我需要将此列更新为较低的精度,称之为m 所以mn 当我运行命令时: ALTER TABLE my_TABLE 更改列my_列 数字类型(m,2) 我得到以下错误:数值字段溢出 我理解这是因为我在表中存储的值的精度大于m(我希望新精度是什么)。我有没有办法告诉博士后改变精度,忽略丢失的精度? 前 如果n=20,m=15 我在my_列中有一个值是999999999999999,这个精度是17如果我没有弄错的话,我能告诉postgres

我在postgres数据库模式的表中有一个数字列,它的精度为
n

我需要将此列更新为较低的精度,称之为
m

所以
m
n

当我运行命令时:

ALTER TABLE my_TABLE
更改列my_列
数字类型(m,2)
我得到以下错误:
数值字段溢出

我理解这是因为我在表中存储的值的精度大于
m
(我希望新精度是什么)。我有没有办法告诉博士后改变精度,忽略丢失的精度? 前

如果n=20,m=15
我在
my_列
中有一个值是999999999999999,这个精度是17如果我没有弄错的话,我能告诉postgres忽略丢失的精度并在我更改表/列时将新值保存为999999999999999吗?

您可以使用
使用
来提供转换表达式:

alter table t alter column col
    type numeric(2) using (case when col >= 100 then 99 else col end);

是一个数字小提琴。

对于小数点左侧的数字,它不是这样工作的。