v9-0013-error-safe-for-casting-date-to-other-types-per-pg_cast.patch
text/x-patch
Filename: v9-0013-error-safe-for-casting-date-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 v9-0013
Subject: error safe for casting date to other types per pg_cast
| File | + | − |
|---|---|---|
| src/backend/utils/adt/date.c | 20 | 2 |
From 52145f4ed22021d5eab95886b246076425bd0382 Mon Sep 17 00:00:00 2001
From: jian he <jian.universality@gmail.com>
Date: Thu, 9 Oct 2025 18:42:50 +0800
Subject: [PATCH v9 13/19] error safe for casting date 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 = 'date'::regtype
order by castsource::regtype;
castsource | casttarget | castfunc | castcontext | castmethod | prosrc | proname
------------+-----------------------------+----------+-------------+------------+------------------+-------------
date | timestamp without time zone | 2024 | i | f | date_timestamp | timestamp
date | timestamp with time zone | 1174 | i | f | date_timestamptz | timestamptz
(2 rows)
discussion: https://postgr.es/m/CADkLM=fv1JfY4Ufa-jcwwNbjQixNViskQ8jZu3Tz_p656i_4hQ@mail.gmail.com
---
src/backend/utils/adt/date.c | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/src/backend/utils/adt/date.c b/src/backend/utils/adt/date.c
index 344f58b92f7..c7a3cde2d81 100644
--- a/src/backend/utils/adt/date.c
+++ b/src/backend/utils/adt/date.c
@@ -1350,7 +1350,16 @@ date_timestamp(PG_FUNCTION_ARGS)
DateADT dateVal = PG_GETARG_DATEADT(0);
Timestamp result;
- result = date2timestamp(dateVal);
+ if (likely(!fcinfo->context))
+ result = date2timestamp(dateVal);
+ else
+ {
+ int overflow;
+
+ result = date2timestamp_opt_overflow(dateVal, &overflow);
+ if (overflow != 0)
+ PG_RETURN_NULL();
+ }
PG_RETURN_TIMESTAMP(result);
}
@@ -1435,7 +1444,16 @@ date_timestamptz(PG_FUNCTION_ARGS)
DateADT dateVal = PG_GETARG_DATEADT(0);
TimestampTz result;
- result = date2timestamptz(dateVal);
+ if (likely(!fcinfo->context))
+ result = date2timestamptz(dateVal);
+ else
+ {
+ int overflow;
+ result = date2timestamptz_opt_overflow(dateVal, &overflow);
+
+ if (overflow != 0)
+ PG_RETURN_NULL();
+ }
PG_RETURN_TIMESTAMP(result);
}
--
2.34.1