parse_duration(trino)函数在PostgreSQL中的使用

huangapple go评论91阅读模式
英文:

parse_duration (trino) fuction in PostgreSQL

问题

我有一个持续时间字段,比如21,600秒,我想将它更改为时间戳持续时间,以便能够将它添加到其他时间戳中。
在Trino中,我能够使用以下代码:

parse_duration(concat(cast(cast(update_interval as int) as varchar),'s'))

但是在PostgreSQL中我无法实现相同的功能。

在图片中分享了目标:
parse_duration(trino)函数在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.

Shared on a pic the goal:
parse_duration(trino)函数在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

Demo

huangapple
  • 本文由 发表于 2023年7月24日 17:47:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76753246.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定