pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Break out xxx2yyy_opt_overflow APIs for more datetime conversion
Date: Thu, 03 Jul 2025 20:30:46 +0000
Message-ID: <E1uXQZy-004ZLj-1E@gemulon.postgresql.org> (raw)

Break out xxx2yyy_opt_overflow APIs for more datetime conversions.

Previous commits invented timestamp2timestamptz_opt_overflow,
date2timestamp_opt_overflow, and date2timestamptz_opt_overflow
functions to perform non-error-throwing conversions between
datetime types.  This patch completes the set by adding
timestamp2date_opt_overflow, timestamptz2date_opt_overflow,
and timestamptz2timestamp_opt_overflow.

In addition, adjust timestamp2timestamptz_opt_overflow so that it
doesn't throw error if timestamp2tm fails, but treats that as an
overflow case.  The situation probably can't arise except with an
invalid timestamp value, and I can't think of a way that that would
happen except data corruption.  However, it's pretty silly to have a
function whose entire reason for existence is to not throw errors for
out-of-range inputs nonetheless throw an error for out-of-range input.

The new APIs are not used in this patch, but will be needed in
upcoming btree_gin changes.

Author: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
Discussion: https://postgr.es/m/262624.1738460652@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/0059bbe1ecaa5f7f19a8b3aae059f352c02e1d88

Modified Files
--------------
src/backend/utils/adt/date.c      | 86 ++++++++++++++++++++++++++++++++++++++-
src/backend/utils/adt/timestamp.c | 81 +++++++++++++++++++++++++++++-------
src/include/utils/date.h          |  2 +
src/include/utils/timestamp.h     |  3 ++
4 files changed, 156 insertions(+), 16 deletions(-)



Message-ID: <E1uXQZy-004ZLj-1E@gemulon.postgresql.org>
Permalink:  ../E1uXQZy-004ZLj-1E@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1uXQZy-004ZLj-1E@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: tgl@sss.pgh.pa.us, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Break out xxx2yyy_opt_overflow APIs for more datetime conversion
  In-Reply-To: <E1uXQZy-004ZLj-1E@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