英文:
parse_duration (trino) fuction in PostgreSQL
问题
我有一个持续时间字段,比如21,600秒,我想将它更改为时间戳持续时间,以便能够将它添加到其他时间戳中。
在Trino中,我能够使用以下代码:
parse_duration(concat(cast(cast(update_interval as int) as varchar),'s'))
但是在PostgreSQL中我无法实现相同的功能。
有人已经做过类似的操作吗?谢谢!
英文:
I have duration field, like 21,600 seconds, and I would like to change it to timestamp duration to be able to add it to another timestamps.
In Trino I was able to use
parse_duration(concat(cast(cast(update_interval as int) as varchar),'s'))
, but I cannot get in PostgreSQL.
Anyone has done the same? thanks!!
答案1
得分: 1
根据我理解,您的原始数据可以转换为整数,因此您可以尝试使用 make_interval
函数:
select make_interval(secs => 10)
要获得所需的输出,您可以尝试类似以下的内容:
select to_char(justify_hours(make_interval(secs => update_interval)), 'DD HH24:MI:SS')
from (select 2592000 as update_interval) t
英文:
As far as I understand your original data is/can be cast to integer, so you can try using make_interval
:
select make_interval(secs => 10)
To get desired output you can try something like the following:
select to_char(justify_hours(make_interval(secs => update_interval)), 'DD HH24:MI:SS')
from (select 2592000 as update_interval) t
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论