Re: date_trunc invalid units with infinite value

Michael Paquier <michael@paquier.xyz>

From: Michael Paquier <michael@paquier.xyz>
To: Joseph Koshakow <koshy44@gmail.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2024-12-05T05:34:41Z
Lists: pgsql-hackers
On Sun, Dec 01, 2024 at 03:09:17PM -0500, Joseph Koshakow wrote:
> When looking at the date_trunc function, I noticed that it wasn't
> rejecting invalid units if the value was infinite. It's slightly
> annoying to fix this, but we already do something very similar for
> date_part. I have attached a patch that would fix this issue, let me
> know if you think it's worth pursuing.

I agree that it is inconsistent that we allow infinite values to go
through this function call even for fields that are not listed as
supported by the documentation.  So, yes, I think that what you are
doing the right thing by applying the check based on the units
supported, but I also doubt that it is something that we could
backpatch as it would cause queries to work now to suddenly break.

Thoughts and comments from others are welcome.
--
Michael

Commits

  1. Improve tests of date_trunc() with infinity and unsupported units

  2. Fix incorrect Datum conversion in timestamptz_trunc_internal()

  3. Improve handling of date_trunc() units for infinite input values