Re: BUG #17496: to_char function resets if interval exceeds 23 hours 59 minutes

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>
Cc: nathandbossart(at)gmail(dot)com, jeff(dot)janes(at)gmail(dot)com, qubzen(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #17496: to_char function resets if interval exceeds 23 hours 59 minutes
Date: 2022-07-18 21:21:30
Message-ID: YtXO2jMXxIRlHJHb@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Fri, Jul 15, 2022 at 04:58:35PM +0900, Kyotaro Horiguchi wrote:
> At Thu, 14 Jul 2022 17:57:32 -0400, Bruce Momjian <bruce(at)momjian(dot)us> wrote in
> > On Tue, May 24, 2022 at 01:11:45PM -0700, Nathan Bossart wrote:
> > > The example provided is more like the former (no hour value), because
> > > "timestamp - timestamp" converts 24-hour intervals into days. In general,
> > > I agree that this probably not a bug. You probably want to ask to_char()
> > > to display the days as well..
>
> On the other hand, "interval + interval" doesn't convert hours into
> days. I expected the math to do normalization.
>
> select INTERVAL '1 day 15hour' + interval '2 day 15 hour';
> ?column?
> -----------------
> 3 days 30:00:00
>
> Is there any means to control over normalization?

Sure, justify_hours():

SELECT INTERVAL '1 day 15hour' + interval '2 day 15 hour';
?column?
-----------------
3 days 30:00:00

SELECT justify_hours(INTERVAL '1 day 15hour' + interval '2 day 15
hour');
justify_hours
-----------------
4 days 06:00:00

--
Bruce Momjian <bruce(at)momjian(dot)us> https://momjian.us
EDB https://enterprisedb.com

Indecision is a decision. Inaction is an action. Mark Batterson

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message David G. Johnston 2022-07-18 22:17:11 Re: BUG #17434: CREATE/DROP DATABASE can be executed in the same transaction with other commands
Previous Message Tom Lane 2022-07-18 20:20:24 Re: BUG #17434: CREATE/DROP DATABASE can be executed in the same transaction with other commands