v8-0014-error-safe-for-casting-interval-to-other-types-per-pg_cast.patch
text/x-patch
Filename: v8-0014-error-safe-for-casting-interval-to-other-types-per-pg_cast.patch
Type: text/x-patch
Part: 7
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch v8-0014
Subject: error safe for casting interval to other types per pg_cast
| File | + | − |
|---|---|---|
| src/backend/utils/adt/date.c | 1 | 1 |
| src/backend/utils/adt/timestamp.c | 2 | 1 |
From 488fab8fb6d4f3be25b347137d743631cff3a7b7 Mon Sep 17 00:00:00 2001
From: jian he <jian.universality@gmail.com>
Date: Thu, 9 Oct 2025 18:43:29 +0800
Subject: [PATCH v8 14/20] error safe for casting interval to other types per
pg_cast
select castsource::regtype, casttarget::regtype, castfunc,
castcontext,castmethod, pp.prosrc, pp.proname from pg_cast pc join pg_proc pp on
pp.oid = pc.castfunc and pc.castfunc > 0
and castsource::regtype = 'interval'::regtype
order by castsource::regtype;
castsource | casttarget | castfunc | castcontext | castmethod | prosrc | proname
------------+------------------------+----------+-------------+------------+----------------+----------
interval | time without time zone | 1419 | a | f | interval_time | time
interval | interval | 1200 | i | f | interval_scale | interval
(2 rows)
discussion: https://postgr.es/m/CADkLM=fv1JfY4Ufa-jcwwNbjQixNViskQ8jZu3Tz_p656i_4hQ@mail.gmail.com
---
src/backend/utils/adt/date.c | 2 +-
src/backend/utils/adt/timestamp.c | 3 ++-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/backend/utils/adt/date.c b/src/backend/utils/adt/date.c
index c7a3cde2d81..4f0f3d26989 100644
--- a/src/backend/utils/adt/date.c
+++ b/src/backend/utils/adt/date.c
@@ -2180,7 +2180,7 @@ interval_time(PG_FUNCTION_ARGS)
TimeADT result;
if (INTERVAL_NOT_FINITE(span))
- ereport(ERROR,
+ ereturn(fcinfo->context, (Datum) 0,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("cannot convert infinite interval to time")));
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c
index 156a4830ffd..7b565cc6d66 100644
--- a/src/backend/utils/adt/timestamp.c
+++ b/src/backend/utils/adt/timestamp.c
@@ -1334,7 +1334,8 @@ interval_scale(PG_FUNCTION_ARGS)
result = palloc(sizeof(Interval));
*result = *interval;
- AdjustIntervalForTypmod(result, typmod, NULL);
+ if (!AdjustIntervalForTypmod(result, typmod, fcinfo->context))
+ PG_RETURN_NULL();
PG_RETURN_INTERVAL_P(result);
}
--
2.34.1