Re: BUG #17496: to_char function resets if interval exceeds 23 hours 59 minutes - Mailing list pgsql-bugs

From Bruce Momjian
Subject Re: BUG #17496: to_char function resets if interval exceeds 23 hours 59 minutes
Date
Msg-id YtXO2jMXxIRlHJHb@momjian.us
Whole thread Raw
In response to Re: BUG #17496: to_char function resets if interval exceeds 23 hours 59 minutes  (Kyotaro Horiguchi <horikyota.ntt@gmail.com>)
List 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@momjian.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@momjian.us>        https://momjian.us
  EDB                                      https://enterprisedb.com

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




pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: BUG #17434: CREATE/DROP DATABASE can be executed in the same transaction with other commands
Next
From: "David G. Johnston"
Date:
Subject: Re: BUG #17434: CREATE/DROP DATABASE can be executed in the same transaction with other commands