Subject: Re: updates for handling optional argument in system functions

From: Mark Wong <[email-masked]>
Date: Thu, 29 Jan 2026 16:15:18 -0800

On Wed, Jan 21, 2026 at 04:45:35PM +0800, Chao Li wrote:
> 
> 
> > On Jan 21, 2026, at 02:15, Mark Wong <[email-masked]> wrote:
> > 
> > Hi everyone,
> > 
> > On Tue, Dec 09, 2025 at 03:28:59PM -0800, Mark Wong wrote:
> >> Hi everyone,
> >> 
> >> I noticed how it was preferred to define optional arguments with the
> >> system functions in system_functions.sql instead of defining them in
> >> pg_proc.dat.
> >> 
> >> I took a gross stab at updating the ones that ended in _ext, which
> >> turned out to be 7 declarations across 6 system functions, and created a
> >> patch per system function, hoping it would be easier to review.
> >> 
> >> Perhaps the most interesting thing to share is the total reduction of
> >> the lines of code, although system_functions.sql only grows:
> >> 
> >> src/backend/catalog/system_functions.sql |  49 ++++++++
> >> src/backend/utils/adt/ruleutils.c        | 130 ----------------------
> >> src/include/catalog/pg_proc.dat          |  36 ++----
> >> 3 files changed, 56 insertions(+), 159 deletions(-)
> >> 
> >> 
> >> Is that something we want?
> > 
> > I fixed an error caught by the address sanitizer in CI [1] and am uploading a
> > new patchset.  The only change is to 2 lines in
> > v2-0005-Handle-pg_get_expr-default-args-in-system_functio.patch to update a
> > call to pg_get_expr with the correct number of arguments in tablecmds.c.
> > 
> > Regards,
> > Mark
> > 
> > [1] https://cirrus-ci.com/task/6109065824174080
> 
> Hi Mark,
> 
> Thanks for the patch. After reviewing it, I have mixed feelings. From one side, it removes some redundant code, which is good. In the other side, I doubt if we should delete proc entries from pg_proc.c? Say, there is a view that uses a proc to be deleted, the proc OID is stored with the view, then after an upgrade, the view would be broken. From this perspective, should we retain the old proc entries and only point them to the new functions?

I don't have a solution for the case of a view storing the OID, but Álvaro
Herrera suggested to me to at least try preventing those OIDs from being
reused.

I've attached a v3 patch set that introduces src/include/catalog/pg_retired.dat
to store previously used OIDs and procedure names that the scripts unused_oids
and renumber_oids.pl can consume to prevent the reuse of retired OIDs.

Maybe that can also be used towards finding that particular solution...

Regards,
Mark
-- 
Mark Wong <[email-masked]>
EDB https://enterprisedb.com

---

From: Andreas Karlsson <[email-masked]>
Date: Wed, 18 Feb 2026 22:56:56 +0100

> Maybe that can also be used towards finding that particular solution...
I am not sure what can be done, breaking people's databases on 
pg_upgrade is certainly not nice and detecting that function oid has 
been used anywhere in a database sounds painful, especially since there 
are no references to system oids in pg_depend, right?

That said this patch should be updated to use the new support for 
default values in BKI files.[1]

https://git.postgresql.org/cgit/postgresql.git/commit/?id=759b03b24ce96f0ba6d734b570d1a6f4a0fb1177

Andreas

---

From: Mark Wong <[email-masked]>
Date: Thu, 26 Feb 2026 11:43:30 -0800

On Wed, Feb 18, 2026 at 10:56:56PM +0100, Andreas Karlsson wrote:
> I am not sure what can be done, breaking people's databases on pg_upgrade is
> certainly not nice and detecting that function oid has been used anywhere in
> a database sounds painful, especially since there are no references to
> system oids in pg_depend, right?
> 
> That said this patch should be updated to use the new support for default
> values in BKI files.[1]
> 

I have attached a new set of patches.  v4 is now using the new support for
default values.

Summary of additional changes:

* I've removed the retired OID tracking, but can certainly add that back if we
  decide it will be useful
* Caught a bug where I wasn't using BoolGetDatum() with DirectFunctionCall3
  with pg_get_expr()

Regards,
Mark
>From fdca206df20d4586f209cbb108761532f0b2935a Mon Sep 17 00:00:00 2001
From: Mark Wong <[email-masked]>
Date: Mon, 8 Dec 2025 15:41:07 -0800
Subject: [PATCH v4 1/6] Handle pg_get_ruledef default args in
 system_functions.sql

Modernize pg_get_ruledef to use proargdefaults for optional pretty
argument.
---
 src/backend/utils/adt/ruleutils.c | 18 ------------------
 src/include/catalog/pg_proc.dat   |  6 ++----
 2 files changed, 2 insertions(+), 22 deletions(-)

diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index f16f1535785..31e773fb32e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -559,24 +559,6 @@ static void get_json_table_nested_columns(TableFunc *tf, JsonTablePlan *plan,
  */
 Datum
 pg_get_ruledef(PG_FUNCTION_ARGS)
-{
-	Oid			ruleoid = PG_GETARG_OID(0);
-	int			prettyFlags;
-	char	   *res;
-
-	prettyFlags = PRETTYFLAG_INDENT;
-
-	res = pg_get_ruledef_worker(ruleoid, prettyFlags);
-
-	if (res == NULL)
-		PG_RETURN_NULL();
-
-	PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_ruledef_ext(PG_FUNCTION_ARGS)
 {
 	Oid			ruleoid = PG_GETARG_OID(0);
 	bool		pretty = PG_GETARG_BOOL(1);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index dac40992cbc..b935b6f14c0 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3962,9 +3962,6 @@
   proargtypes => 'oid oid', prosrc => 'oidge' },
 
 # System-view support functions
-{ oid => '1573', descr => 'source text of a rule',
-  proname => 'pg_get_ruledef', provolatile => 's', prorettype => 'text',
-  proargtypes => 'oid', prosrc => 'pg_get_ruledef' },
 { oid => '1640', descr => 'select statement of a view',
   proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
   prorettype => 'text', proargtypes => 'text',
@@ -8516,7 +8513,8 @@
 # System-view support functions with pretty-print option
 { oid => '2504', descr => 'source text of a rule with pretty-print option',
   proname => 'pg_get_ruledef', provolatile => 's', prorettype => 'text',
-  proargtypes => 'oid bool', prosrc => 'pg_get_ruledef_ext' },
+  proargtypes => 'oid bool', proargnames => '{rule,pretty}',
+  proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
 { oid => '2505',
   descr => 'select statement of a view with pretty-print option',
   proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
-- 
2.43.0

>From 13ce84d431a34a78d9715b299d8f9b33b8861290 Mon Sep 17 00:00:00 2001
From: Mark Wong <[email-masked]>
Date: Tue, 9 Dec 2025 09:33:21 -0800
Subject: [PATCH v4 2/6] Handle pg_get_viewdef default args in
 system_functions.sql

Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
 src/backend/utils/adt/ruleutils.c | 44 -------------------------------
 src/include/catalog/pg_proc.dat   | 13 +++------
 2 files changed, 4 insertions(+), 53 deletions(-)

diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 31e773fb32e..328f994547e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -659,25 +659,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
  */
 Datum
 pg_get_viewdef(PG_FUNCTION_ARGS)
-{
-	/* By OID */
-	Oid			viewoid = PG_GETARG_OID(0);
-	int			prettyFlags;
-	char	   *res;
-
-	prettyFlags = PRETTYFLAG_INDENT;
-
-	res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
-	if (res == NULL)
-		PG_RETURN_NULL();
-
-	PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
 {
 	/* By OID */
 	Oid			viewoid = PG_GETARG_OID(0);
@@ -717,31 +698,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
 
 Datum
 pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
-	/* By qualified name */
-	text	   *viewname = PG_GETARG_TEXT_PP(0);
-	int			prettyFlags;
-	RangeVar   *viewrel;
-	Oid			viewoid;
-	char	   *res;
-
-	prettyFlags = PRETTYFLAG_INDENT;
-
-	/* Look up view name.  Can't lock it - we might not have privileges. */
-	viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
-	viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
-	res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
-	if (res == NULL)
-		PG_RETURN_NULL();
-
-	PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
 {
 	/* By qualified name */
 	text	   *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index b935b6f14c0..166ae4b5645 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3962,13 +3962,6 @@
   proargtypes => 'oid oid', prosrc => 'oidge' },
 
 # System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
-  proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
-  prorettype => 'text', proargtypes => 'text',
-  prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
-  proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
-  prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
 { oid => '1642', descr => 'role name by OID (with fallback)',
   proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
   proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8519,12 +8512,14 @@
   descr => 'select statement of a view with pretty-print option',
   proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
   prorettype => 'text', proargtypes => 'text bool',
-  prosrc => 'pg_get_viewdef_name_ext' },
+  proargnames => '{view,pretty}', proargdefaults => '{false}',
+  prosrc => 'pg_get_viewdef_name' },
 { oid => '2506',
   descr => 'select statement of a view with pretty-print option',
   proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
   prorettype => 'text', proargtypes => 'oid bool',
-  prosrc => 'pg_get_viewdef_ext' },
+  proargnames => '{view,pretty}', proargdefaults => '{false}',
+  prosrc => 'pg_get_viewdef' },
 { oid => '3159',
   descr => 'select statement of a view with pretty-printing and specified line wrapping',
   proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
-- 
2.43.0

>From e4f7ae2de2a1e0cc131dc35ecf416832e27c6b20 Mon Sep 17 00:00:00 2001
From: Mark Wong <[email-masked]>
Date: Tue, 9 Dec 2025 10:02:15 -0800
Subject: [PATCH v4 3/6] Handle pg_get_indexdef default args in
 system_functions.sql

Modernize pg_get_indexdef to use proargdefaults to handle the optional
column and pretty argument.
---
 src/backend/utils/adt/ruleutils.c | 20 --------------------
 src/include/catalog/pg_proc.dat   |  6 ++----
 2 files changed, 2 insertions(+), 24 deletions(-)

diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 328f994547e..b40158d30bb 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -1115,26 +1115,6 @@ pg_get_triggerdef_worker(Oid trigid, bool pretty)
  */
 Datum
 pg_get_indexdef(PG_FUNCTION_ARGS)
-{
-	Oid			indexrelid = PG_GETARG_OID(0);
-	int			prettyFlags;
-	char	   *res;
-
-	prettyFlags = PRETTYFLAG_INDENT;
-
-	res = pg_get_indexdef_worker(indexrelid, 0, NULL,
-								 false, false,
-								 false, false,
-								 prettyFlags, true);
-
-	if (res == NULL)
-		PG_RETURN_NULL();
-
-	PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-Datum
-pg_get_indexdef_ext(PG_FUNCTION_ARGS)
 {
 	Oid			indexrelid = PG_GETARG_OID(0);
 	int32		colno = PG_GETARG_INT32(1);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 166ae4b5645..7e45cbcb93d 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3965,9 +3965,6 @@
 { oid => '1642', descr => 'role name by OID (with fallback)',
   proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
   proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
-{ oid => '1643', descr => 'index description',
-  proname => 'pg_get_indexdef', provolatile => 's', prorettype => 'text',
-  proargtypes => 'oid', prosrc => 'pg_get_indexdef' },
 { oid => '3415', descr => 'extended statistics object description',
   proname => 'pg_get_statisticsobjdef', provolatile => 's',
   prorettype => 'text', proargtypes => 'oid',
@@ -8528,7 +8525,8 @@
 { oid => '2507',
   descr => 'index description (full create statement or single expression) with pretty-print option',
   proname => 'pg_get_indexdef', provolatile => 's', prorettype => 'text',
-  proargtypes => 'oid int4 bool', prosrc => 'pg_get_indexdef_ext' },
+  proargtypes => 'oid int4 bool', proargnames => '{index,column,pretty}',
+  proargdefaults => '{0,false}', prosrc => 'pg_get_indexdef' },
 { oid => '2508', descr => 'constraint description with pretty-print option',
   proname => 'pg_get_constraintdef', provolatile => 's', prorettype => 'text',
   proargtypes => 'oid bool', prosrc => 'pg_get_constraintdef_ext' },
-- 
2.43.0

>From 07eac504026eb72bc16afe72bdcee00e3d1d5b26 Mon Sep 17 00:00:00 2001
From: Mark Wong <[email-masked]>
Date: Tue, 9 Dec 2025 10:59:41 -0800
Subject: [PATCH v4 4/6] Handle pg_get_constraintdef default args in
 system_functions.sql

Modernize pg_get_constraintdef to use proargdefaults to handle the
optional pretty argument.
---
 src/backend/utils/adt/ruleutils.c | 17 -----------------
 src/include/catalog/pg_proc.dat   |  6 ++----
 2 files changed, 2 insertions(+), 21 deletions(-)

diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index b40158d30bb..03550f0d80b 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -2062,23 +2062,6 @@ pg_get_partconstrdef_string(Oid partitionId, char *aliasname)
  */
 Datum
 pg_get_constraintdef(PG_FUNCTION_ARGS)
-{
-	Oid			constraintId = PG_GETARG_OID(0);
-	int			prettyFlags;
-	char	   *res;
-
-	prettyFlags = PRETTYFLAG_INDENT;
-
-	res = pg_get_constraintdef_worker(constraintId, false, prettyFlags, true);
-
-	if (res == NULL)
-		PG_RETURN_NULL();
-
-	PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-Datum
-pg_get_constraintdef_ext(PG_FUNCTION_ARGS)
 {
 	Oid			constraintId = PG_GETARG_OID(0);
 	bool		pretty = PG_GETARG_BOOL(1);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 7e45cbcb93d..1d1b24a8f4c 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3987,9 +3987,6 @@
 { oid => '1662', descr => 'trigger description',
   proname => 'pg_get_triggerdef', provolatile => 's', prorettype => 'text',
   proargtypes => 'oid', prosrc => 'pg_get_triggerdef' },
-{ oid => '1387', descr => 'constraint description',
-  proname => 'pg_get_constraintdef', provolatile => 's', prorettype => 'text',
-  proargtypes => 'oid', prosrc => 'pg_get_constraintdef' },
 { oid => '1716', descr => 'deparse an encoded expression',
   proname => 'pg_get_expr', provolatile => 's', prorettype => 'text',
   proargtypes => 'pg_node_tree oid', prosrc => 'pg_get_expr' },
@@ -8529,7 +8526,8 @@
   proargdefaults => '{0,false}', prosrc => 'pg_get_indexdef' },
 { oid => '2508', descr => 'constraint description with pretty-print option',
   proname => 'pg_get_constraintdef', provolatile => 's', prorettype => 'text',
-  proargtypes => 'oid bool', prosrc => 'pg_get_constraintdef_ext' },
+  proargtypes => 'oid bool', proargnames => '{constraint,pretty}',
+  proargdefaults => '{false}', prosrc => 'pg_get_constraintdef' },
 { oid => '2509',
   descr => 'deparse an encoded expression with pretty-print option',
   proname => 'pg_get_expr', provolatile => 's', prorettype => 'text',
-- 
2.43.0

>From 49c9382e0ab6a18b687e7fb391b837b8ab33c360 Mon Sep 17 00:00:00 2001
From: Mark Wong <[email-masked]>
Date: Tue, 9 Dec 2025 11:17:56 -0800
Subject: [PATCH v4 5/6] Handle pg_get_expr default args in
 system_functions.sql

Modernize pg_get_expr to use proargdefaults to handle the optional
pretty argument.  That also means any direct function calls now needs to
set the pretty parameter.
---
 src/backend/commands/tablecmds.c  |  5 +++--
 src/backend/utils/adt/ruleutils.c | 17 -----------------
 src/include/catalog/pg_proc.dat   |  7 +++----
 3 files changed, 6 insertions(+), 23 deletions(-)

diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index b04b0dbd2a0..a523a512949 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -17477,8 +17477,9 @@ decompile_conbin(HeapTuple contup, TupleDesc tupdesc)
 	if (isnull)
 		elog(ERROR, "null conbin for constraint %u", con->oid);
 
-	expr = DirectFunctionCall2(pg_get_expr, attr,
-							   ObjectIdGetDatum(con->conrelid));
+	expr = DirectFunctionCall3(pg_get_expr, attr,
+							   ObjectIdGetDatum(con->conrelid),
+							   BoolGetDatum(false));
 	return TextDatumGetCString(expr);
 }
 
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 03550f0d80b..a70807e84ca 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -2574,23 +2574,6 @@ decompile_column_index_array(Datum column_index_array, Oid relId,
  */
 Datum
 pg_get_expr(PG_FUNCTION_ARGS)
-{
-	text	   *expr = PG_GETARG_TEXT_PP(0);
-	Oid			relid = PG_GETARG_OID(1);
-	text	   *result;
-	int			prettyFlags;
-
-	prettyFlags = PRETTYFLAG_INDENT;
-
-	result = pg_get_expr_worker(expr, relid, prettyFlags);
-	if (result)
-		PG_RETURN_TEXT_P(result);
-	else
-		PG_RETURN_NULL();
-}
-
-Datum
-pg_get_expr_ext(PG_FUNCTION_ARGS)
 {
 	text	   *expr = PG_GETARG_TEXT_PP(0);
 	Oid			relid = PG_GETARG_OID(1);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 1d1b24a8f4c..69c1e5bb264 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3987,9 +3987,6 @@
 { oid => '1662', descr => 'trigger description',
   proname => 'pg_get_triggerdef', provolatile => 's', prorettype => 'text',
   proargtypes => 'oid', prosrc => 'pg_get_triggerdef' },
-{ oid => '1716', descr => 'deparse an encoded expression',
-  proname => 'pg_get_expr', provolatile => 's', prorettype => 'text',
-  proargtypes => 'pg_node_tree oid', prosrc => 'pg_get_expr' },
 { oid => '1665', descr => 'name of sequence for a serial column',
   proname => 'pg_get_serial_sequence', provolatile => 's', prorettype => 'text',
   proargtypes => 'text text', prosrc => 'pg_get_serial_sequence' },
@@ -8531,7 +8528,9 @@
 { oid => '2509',
   descr => 'deparse an encoded expression with pretty-print option',
   proname => 'pg_get_expr', provolatile => 's', prorettype => 'text',
-  proargtypes => 'pg_node_tree oid bool', prosrc => 'pg_get_expr_ext' },
+  proargtypes => 'pg_node_tree oid bool',
+  proargnames => '{expr,relation,pretty}', proargdefaults => '{false}',
+  prosrc => 'pg_get_expr' },
 { oid => '2510', descr => 'get the prepared statements for this session',
   proname => 'pg_prepared_statement', prorows => '1000', proretset => 't',
   provolatile => 's', proparallel => 'r', prorettype => 'record',
-- 
2.43.0

>From 8d48c5a3935efb8e50b5b8d51a240336e124e5d1 Mon Sep 17 00:00:00 2001
From: Mark Wong <[email-masked]>
Date: Tue, 9 Dec 2025 11:51:39 -0800
Subject: [PATCH v4 6/6] Handle pg_get_triggerdef default args in
 system_functions.sql

Modernize pg_get_triggerdef to use proargdefaults to handle the optional
pretty argument.
---
 src/backend/utils/adt/ruleutils.c | 14 --------------
 src/include/catalog/pg_proc.dat   |  6 ++----
 2 files changed, 2 insertions(+), 18 deletions(-)

diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index a70807e84ca..27be4501e12 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -808,20 +808,6 @@ pg_get_viewdef_worker(Oid viewoid, int prettyFlags, int wrapColumn)
  */
 Datum
 pg_get_triggerdef(PG_FUNCTION_ARGS)
-{
-	Oid			trigid = PG_GETARG_OID(0);
-	char	   *res;
-
-	res = pg_get_triggerdef_worker(trigid, false);
-
-	if (res == NULL)
-		PG_RETURN_NULL();
-
-	PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-Datum
-pg_get_triggerdef_ext(PG_FUNCTION_ARGS)
 {
 	Oid			trigid = PG_GETARG_OID(0);
 	bool		pretty = PG_GETARG_BOOL(1);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 69c1e5bb264..b43cbb62b82 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3984,9 +3984,6 @@
   proname => 'pg_get_partition_constraintdef', provolatile => 's',
   prorettype => 'text', proargtypes => 'oid',
   prosrc => 'pg_get_partition_constraintdef' },
-{ oid => '1662', descr => 'trigger description',
-  proname => 'pg_get_triggerdef', provolatile => 's', prorettype => 'text',
-  proargtypes => 'oid', prosrc => 'pg_get_triggerdef' },
 { oid => '1665', descr => 'name of sequence for a serial column',
   proname => 'pg_get_serial_sequence', provolatile => 's', prorettype => 'text',
   proargtypes => 'text text', prosrc => 'pg_get_serial_sequence' },
@@ -8566,7 +8563,8 @@
   prosrc => 'pg_timezone_names' },
 { oid => '2730', descr => 'trigger description with pretty-print option',
   proname => 'pg_get_triggerdef', provolatile => 's', prorettype => 'text',
-  proargtypes => 'oid bool', prosrc => 'pg_get_triggerdef_ext' },
+  proargtypes => 'oid bool', proargnames => '{trigger,pretty}',
+  proargdefaults => '{false}', prosrc => 'pg_get_triggerdef' },
 
 # asynchronous notifications
 { oid => '3035',
-- 
2.43.0

---

From: Mark Wong <[email-masked]>
Date: Wed, 11 Mar 2026 20:28:14 -0700

On Tue, Mar 03, 2026 at 05:23:58PM +0100, Álvaro Herrera wrote:
> On 2026-Jan-29, Mark Wong wrote:
> 
> Thinking about this again, I wonder where did we get the idea that
> reusing OIDs would be a problem.  How exactly would this happen?  When
> you pg_upgrade, your views are taken from a `pg_dump --binary-upgrade`
> of the original server, and then recreated using the text
> representation of the DDL.  We don't pass the function OIDs in any way
> from the old server to the new server.  And there's no other way (than
> pg_upgrade) to go from one major version to the next one where the OID
> has been reused.
> 
> So why did we think this was an actual problem?

I'm not sure.  I think I see the OID of a function get used in some places
likes rewriteDefine.c and parse_funcs.c, but I'm not sure if I see a function
OID get written out and re-read for a function name lookup in an upgrade code
path, yet...

Regards,
Mark