postgresql - 在 Postgres 中,如何舍入提取时代的回报
问题描述
Linux 上的 psql(9.6.7,服务器 11.3)
鉴于这个简单的表...
dvdb=> select * from delme;
start_dt | end_dt
------------------------+------------------------
2020-03-01 00:00:00-05 | 2020-03-03 12:34:56-05
(1 row)
我想要时间增量的小时数,四舍五入到最接近的十分之一小时。我能走到这一步...
dvdb=> select extract(epoch from age(end_dt,start_dt)/3600) from delme;
date_part
-----------
60.582222
(1 row)
但似乎不能圆....
dvdb=> select round(extract(epoch from age(end_dt,start_dt)/3600),1) from delme;
ERROR: function round(double precision, integer) does not exist
LINE 1: select round(extract(epoch from age(end_dt,start_dt)/3600),1...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
dvdb=>
dvdb=> select round(cast(extract(epoch from age(end_dt,start_dt)/3600) as float),1) from delme;
ERROR: function round(double precision, integer) does not exist
LINE 1: select round(cast(extract(epoch from age(end_dt,start_dt)/36...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
dvdb=>
我想我没有正确理解 round ,它想要的第一个 arg 类型......
dvdb=> select round(123.456,1);
round
-------
123.5
(1 row)
dvdb=> select round(cast(123.456 as float),1);
ERROR: function round(double precision, integer) does not exist
LINE 1: select round(cast(123.456 as float),1);
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
dvdb=>
解决方案
我想我明白了...
dvdb=> select round(cast(extract(epoch from age(end_dt,start_dt)/3600) as numeric),1) from delme;
round
-------
60.6
(1 row)
推荐阅读
- ios - FirebaseChat Swift4
- genymotion - Genymotion 安装 GApp 失败
- javascript - 道具没有传递给另一个组件
- php - 跟随链接时无法正确加载 Css
- postgresql-9.5 - 在 CASE-WHEN 之后无法按别名过滤。列不存在
- java - gradle 如何决定 file.encoding JVM 系统属性?
- javascript - NgModule - 如何接收配置并将其传递给 Angular 中嵌套的导入模块?
- r - 将较大的数字区间变成指定范围的较小区间
- c# - 删除 NuGet 包的依赖 NuGet 包
- javascript - webpack 开发服务器不运行