pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Improve handling of date_trunc() units for infinite input values
Date: Fri, 27 Dec 2024 04:41:24 +0000
Message-ID: <E1tR2A8-001YJJ-CQ@gemulon.postgresql.org> (raw)

Improve handling of date_trunc() units for infinite input values

Previously, if an infinite value was passed to date_trunc(), then the
same infinite value would always be returned regardless of the field
unit given by the caller.  This commit updates the function so that an
error is returned when an invalid unit is passed to date_trunc() with an
infinite value.

This matches the behavior of date_trunc() with a finite value and
date_part() with an infinite value, making the handling of interval,
timestamp and timestamptz more consistent across the board for these two
functions.

Some tests are added to cover all these new failure cases, with an
unsupported unit and infinite values for the three data types.  There
were no test cases in core that checked all these patterns up to now.

Author: Joseph Koshakow
Discussion: https://postgr.es/m/CAAvxfHc4084dGzEJR0_pBZkDuqbPGc5wn7gK_M0XR_kRiCdUJQ@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/d85ce012f99f63249bb45a78fcecb7a2383920b1

Modified Files
--------------
src/backend/utils/adt/timestamp.c         | 121 +++++++++++++++++++++++++-----
src/test/regress/expected/interval.out    |   9 +++
src/test/regress/expected/timestamp.out   |   2 +
src/test/regress/expected/timestamptz.out |   4 +
src/test/regress/sql/interval.sql         |   8 ++
src/test/regress/sql/timestamp.sql        |   2 +
src/test/regress/sql/timestamptz.sql      |   4 +
7 files changed, 131 insertions(+), 19 deletions(-)



Message-ID: <E1tR2A8-001YJJ-CQ@gemulon.postgresql.org>
Permalink:  ../E1tR2A8-001YJJ-CQ@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1tR2A8-001YJJ-CQ@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: michael@paquier.xyz, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Improve handling of date_trunc() units for infinite input values
  In-Reply-To: <E1tR2A8-001YJJ-CQ@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox