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

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Nathan Bossart <nathandbossart(at)gmail(dot)com>
Cc: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>, 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-07-14 21:57:32
Message-ID: YtCRTLYoAgGcIenX@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Tue, May 24, 2022 at 01:11:45PM -0700, Nathan Bossart wrote:
> 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..

Well, if we did that then this would be odd:

SELECT to_char(INTERVAL '2 day', 'DD HH24:MI');
to_char
----------
02 00:00

or this:

SELECT to_char(INTERVAL '2 day 4 hours', 'DD HH24:MI');
to_char
----------
02 04: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

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Bruce Momjian 2022-07-14 23:49:32 Re: BUG #17434: CREATE/DROP DATABASE can be executed in the same transaction with other commands
Previous Message Tom Lane 2022-07-14 18:24:09 Re: BUG #17550: inet type doesn't accept alternate notations of ipv4 addresses