Postgres“规范化”间隔输出

时间:2016-12-20 16:45:20

标签: postgresql

回答simple question我被问及如何“转换”2 days 31:09:343 days 07:09:34。我不能提出任何不那么丑陋的东西,然后再执行一次时差,就像这里:

t=# with a as (
  select cast('2 days 31:09:34.607843' as interval) i
)
select i, now() +i -now() wheel,i+interval '1 minute'
from a;
           i            |         wheel          |        ?column?
------------------------+------------------------+------------------------
 2 days 31:09:34.607843 | 3 days 07:09:34.607843 | 2 days 31:10:34.607843
(1 row)

时间:0.232毫秒

请告诉我将'25 hours'::interval“翻译”为'1 day 1 hour'::interval

的正确方法

1 个答案:

答案 0 :(得分:1)

使用justify_interval()

with a as (
  select cast('2 days 31:09:34.607843' as interval) i
)
select justify_interval(i)
from a;

输出

    justify_interval
------------------------
 3 days 07:09:34.607843
(1 row)