Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.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
Postgresql 更新不带小数点和零的数字字段_Postgresql - Fatal编程技术网

Postgresql 更新不带小数点和零的数字字段

Postgresql 更新不带小数点和零的数字字段,postgresql,Postgresql,我正在尝试更新数字字段。但字段不能在小数点后有零。但我试图提取的表中包含87.00、90.00100.00等数据。。如何在没有小数点和零的情况下更新 示例:百分比是一个数字字段。 更新值可用100.00、90.00等 update table1 set percent =(tmpercent as integer) from table2 where table2.custid=table1.custoid; ) 给出了错误 表1: CustID Percent(numeric)

我正在尝试更新数字字段。但字段不能在小数点后有零。但我试图提取的表中包含87.00、90.00100.00等数据。。如何在没有小数点和零的情况下更新

示例:百分比是一个数字字段。 更新值可用100.00、90.00等

update table1 
  set percent =(tmpercent as integer) 
from table2
where table2.custid=table1.custoid;
)

给出了错误

表1:

CustID   Percent(numeric)
1           90
2           80
表2:

CustomID  tmpPercent(varchar)
1              87.00
2              90.00 

我经常使用类型转换
::FLOAT::NUMERIC
来消除数字中多余的分数零

或者可以使用
TRUNC()
函数强制分数截断

试一试

更新表1
设置百分比=tmpercent::FLOAT::NUMERIC
来自表2
其中table2.custid=table1.custoid;

更新表1
设置百分比=TRUNC(tmpercent::NUMERIC)
来自表2
其中table2.custid=table1.custoid;

这将取决于表中如何指定
数值
字段。从这里开始:

我们使用以下术语:数字的精度是整数中有效位数的总数,即小数点两侧的位数。数字的小数位数是小数点右侧小数部分的小数位数计数。所以数字23.5141的精度为6,刻度为4。可以认为整数的刻度为零

数字(精度、比例)

因此,如果字段的比例大于0,则小数点右侧将显示0,除非将
scale
设置为0。例如:

create table numeric_test (num_fld numeric(5,2), num_fld_0 numeric(5,0));

insert into numeric_test (num_fld, num_fld_0) values ('90.0', '90.0');

select * from numeric_test ;
 num_fld | num_fld_0 
---------+-----------
   90.00 |        90

insert into numeric_test (num_fld, num_fld_0) values ('90.5', '90.5');

select * from numeric_test ;
 num_fld | num_fld_0 
---------+-----------
   90.00 |        90
   90.50 |        91

insert into numeric_test (num_fld, num_fld_0) values ('90.0'::float, '90.0'::float);

select * from numeric_test ;
 num_fld | num_fld_0 
---------+-----------
   90.00 |        90
   90.50 |        91
   90.00 |        90



使用
scale
0表示您基本上已经创建了一个整数字段。如果您有一个
刻度
>0,那么您将在字段中得到小数。

请添加表格定义。