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

From Nathan Bossart
Subject Re: BUG #17496: to_char function resets if interval exceeds 23 hours 59 minutes
Date
Msg-id 20220524201145.GA1253717@nathanxps13
Whole thread Raw
In response to Re: BUG #17496: to_char function resets if interval exceeds 23 hours 59 minutes  (Jeff Janes <jeff.janes@gmail.com>)
Responses Re: BUG #17496: to_char function resets if interval exceeds 23 hours 59 minutes
List pgsql-bugs
On Tue, May 24, 2022 at 03:55:49PM -0400, Jeff Janes wrote:
> On Tue, May 24, 2022, 3:23 PM PG Bug reporting form <noreply@postgresql.org>
>> to_char function resets if interval exceeds 23 hours 59 minutes found at:
>>
>> https://www.postgresql.org/docs/current/functions-formatting.html#FUNCTIONS-FORMATTING-TABLE
>>
>> Tested for both 13 and 14 versions. Check here:
>>
>> https://dbfiddle.uk/?rdbms=postgres_14&fiddle=31f5d8b7e8dbf855e1907e6e8f01d5cf
> 
> 
> I don't see how this is a bug. You told it not to display the days or
> higher units, so it doesn't.

The documentation for this function indicates HH24 can output hour values
higher than 23∴

        <function>to_char(interval)</function> formats <literal>HH</literal> and
        <literal>HH12</literal> as shown on a 12-hour clock, for example zero hours
        and 36 hours both output as <literal>12</literal>, while <literal>HH24</literal>
        outputs the full hour value, which can exceed 23 in
        an <type>interval</type> value.

I see different results depending on how I define the interval:

    postgres=# select to_char(INTERVAL '1 day', 'HH24:MI');
     to_char 
    ---------
     00:00
    (1 row)

    postgres=# select to_char(INTERVAL '24h', 'HH24:MI');
     to_char 
    ---------
     24:00
    (1 row)

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..

-- 
Nathan Bossart
Amazon Web Services: https://aws.amazon.com



pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: Unable to connect to PostgreSQL DB as root user when private key is owned by root with permission 640
Next
From: David Steele
Date:
Subject: Re: Unable to connect to PostgreSQL DB as root user when private key is owned by root with permission 640