postgresql - 更新没有小数点和零的数字字段
问题描述
我正在尝试更新数字字段。但该字段小数点后不能有零。但是我试图提取值的表包含 87.00、90.00、100.00 等数据。如何在没有小数点和零的情况下更新?
示例 :percentage 是一个数字字段。更新可用值 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()
函数强制截断分数
尝试
update table1
set percent = tmpercent::FLOAT::NUMERIC
from table2
where table2.custid=table1.custoid;
或者
update table1
set percent = TRUNC(tmpercent::NUMERIC)
from table2
where table2.custid=table1.custoid;
推荐阅读
- python - 更改 x 轴范围
- javascript - 基于 Javascript 中的过滤器数组的过滤器数组
- tensorflow - 如何安装支持 gpu 的 Keras?
- python - https://s3.zoneame.amazonaws.com/ 的 SSL 验证失败 [SSL: CERTIFICATE_ VERIFY_FAILED] 证书验证失败 (_ssl.c:749)
- rabbitmq - 激活 RabbitMQ 磁盘或内存警报时 spring-cloud-stream-rabbit-binder 如何工作?
- r - NLP 包中的多米诺效应错误/警告?
- linux - 查找日期命令不接受格式的三个时间戳之间的差异
- groovy - 如何在 REST 调用中省略参数
- php - 没有从数据库中获取下拉元素
- javascript - 图层滑块导航在wordpress中的IOS上不起作用