Search code examples
sqlpostgresqlparsingdurationtrino

parse_duration (trino) fuction in 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: enter image description here

Anyone has done the same? thanks!!


Solution

  • 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