v13-0001-error-safe-for-casting-bytea-to-other-types-per-pg_cast.patch
text/x-patch
Filename: v13-0001-error-safe-for-casting-bytea-to-other-types-per-pg_cast.patch
Type: text/x-patch
Part: 19
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 v13-0001
Subject: error safe for casting bytea to other types per pg_cast
| File | + | − |
|---|---|---|
| src/backend/utils/adt/bytea.c | 3 | 3 |
From f4f0e093e60f50b5ee0da5a941bd2e1015be3236 Mon Sep 17 00:00:00 2001
From: jian he <jian.universality@gmail.com>
Date: Sat, 22 Nov 2025 00:08:00 +0800
Subject: [PATCH v13 01/20] error safe for casting bytea 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 ='bytea'::regtype
order by castsource::regtype;
castsource | casttarget | castfunc | castcontext | castmethod | prosrc | proname
------------+------------+----------+-------------+------------+------------+---------
bytea | smallint | 6370 | e | f | bytea_int2 | int2
bytea | integer | 6371 | e | f | bytea_int4 | int4
bytea | bigint | 6372 | e | f | bytea_int8 | int8
(3 rows)
discussion: https://postgr.es/m/CADkLM=fv1JfY4Ufa-jcwwNbjQixNViskQ8jZu3Tz_p656i_4hQ@mail.gmail.com
---
src/backend/utils/adt/bytea.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/backend/utils/adt/bytea.c b/src/backend/utils/adt/bytea.c
index 6e7b914c563..f43ad6b4aff 100644
--- a/src/backend/utils/adt/bytea.c
+++ b/src/backend/utils/adt/bytea.c
@@ -1027,7 +1027,7 @@ bytea_int2(PG_FUNCTION_ARGS)
/* Check that the byte array is not too long */
if (len > sizeof(result))
- ereport(ERROR,
+ ereturn(fcinfo->context, (Datum) 0,
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("smallint out of range"));
@@ -1052,7 +1052,7 @@ bytea_int4(PG_FUNCTION_ARGS)
/* Check that the byte array is not too long */
if (len > sizeof(result))
- ereport(ERROR,
+ ereturn(fcinfo->context, (Datum) 0,
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range"));
@@ -1077,7 +1077,7 @@ bytea_int8(PG_FUNCTION_ARGS)
/* Check that the byte array is not too long */
if (len > sizeof(result))
- ereport(ERROR,
+ ereturn(fcinfo->context, (Datum) 0,
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("bigint out of range"));
--
2.34.1