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

From: Nathan Bossart <nathandbossart(at)gmail(dot)com>
To: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>
Cc: qubzen(at)gmail(dot)com, pgsql-bugs <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-05-24 20:11:45
Message-ID: 20220524201145.GA1253717@nathanxps13
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)postgresql(dot)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

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message David Steele 2022-05-24 20:33:12 Re: Unable to connect to PostgreSQL DB as root user when private key is owned by root with permission 640
Previous Message Tom Lane 2022-05-24 20:05:32 Re: Unable to connect to PostgreSQL DB as root user when private key is owned by root with permission 640