v6-0011-error-safe-for-casting-inet-to-other-types-per-pg_cast.patch

text/x-patch

Filename: v6-0011-error-safe-for-casting-inet-to-other-types-per-pg_cast.patch
Type: text/x-patch
Part: 9
Message: Re: CAST(... ON DEFAULT) - WIP build on top of Error-Safe User Functions

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 v6-0011
Subject: error safe for casting inet to other types per pg_cast
File+
src/backend/utils/adt/network.c 1 1
From fe3598c63639bc81051b0127c15b1aef3e2115f5 Mon Sep 17 00:00:00 2001
From: jian he <jian.universality@gmail.com>
Date: Tue, 5 Aug 2025 15:42:58 +0800
Subject: [PATCH v6 11/18] 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)
---
 src/backend/utils/adt/network.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/backend/utils/adt/network.c b/src/backend/utils/adt/network.c
index 9fd211b2d45..0e2021bcc3c 100644
--- a/src/backend/utils/adt/network.c
+++ b/src/backend/utils/adt/network.c
@@ -1167,7 +1167,7 @@ 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,
+		ereturn(fcinfo->context, (Datum) 0,
 				(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
 				 errmsg("could not format inet value: %m")));
 
-- 
2.34.1