v8-0006-error-safe-for-casting-inet-to-other-types-per-pg_cast.patch
text/x-patch
Filename: v8-0006-error-safe-for-casting-inet-to-other-types-per-pg_cast.patch
Type: text/x-patch
Part: 15
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-0006
Subject: error safe for casting inet to other types per pg_cast
| File | + | − |
|---|---|---|
| src/backend/utils/adt/network.c | 5 | 1 |
From ef691060bbb07a0c8e3d995a70437676bd9dc5f2 Mon Sep 17 00:00:00 2001
From: jian he <jian.universality@gmail.com>
Date: Thu, 9 Oct 2025 15:55:55 +0800
Subject: [PATCH v8 06/20] error safe for casting inet 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 = 'inet'::regtype
order by castsource::regtype;
castsource | casttarget | castfunc | castcontext | castmethod | prosrc | proname
------------+-------------------+----------+-------------+------------+--------------+---------
inet | cidr | 1715 | a | f | inet_to_cidr | cidr
inet | text | 730 | a | f | network_show | text
inet | character varying | 730 | a | f | network_show | text
inet | character | 730 | a | f | network_show | text
(4 rows)
inet_to_cidr is already error safe.
discussion: https://postgr.es/m/CADkLM=fv1JfY4Ufa-jcwwNbjQixNViskQ8jZu3Tz_p656i_4hQ@mail.gmail.com
---
src/backend/utils/adt/network.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/backend/utils/adt/network.c b/src/backend/utils/adt/network.c
index 3cb0ab6829a..f34228763da 100644
--- a/src/backend/utils/adt/network.c
+++ b/src/backend/utils/adt/network.c
@@ -1137,10 +1137,14 @@ network_show(PG_FUNCTION_ARGS)
if (pg_inet_net_ntop(ip_family(ip), ip_addr(ip), ip_maxbits(ip),
tmp, sizeof(tmp)) == NULL)
- ereport(ERROR,
+ {
+ errsave(fcinfo->context,
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("could not format inet value: %m")));
+ PG_RETURN_NULL();
+ }
+
/* Add /n if not present (which it won't be) */
if (strchr(tmp, '/') == NULL)
{
--
2.34.1