agora inbox for pgsql-hackers@postgresql.org
help / color / mirror / Atom feedupdates for handling optional argument in system functions
31+ messages / 10 participants
[nested] [flat]
* updates for handling optional argument in system functions
@ 2025-12-09 23:28 Mark Wong <markwkm@gmail.com>
2025-12-10 09:33 ` Re: updates for handling optional argument in system functions Daniel Gustafsson <daniel@yesql.se>
2026-01-20 18:15 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-02 18:36 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
0 siblings, 3 replies; 31+ messages in thread
From: Mark Wong @ 2025-12-09 23:28 UTC (permalink / raw)
To: pgsql-hackers@lists.postgresql.org
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?
Regards,
Mark
--
Mark Wong <markwkm@gmail.com>
EDB https://enterprisedb.com
From 90229923b475af0169be5cea8819e71425b6a332 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Mon, 8 Dec 2025 15:41:07 -0800
Subject: [PATCH v1 1/6] Handle pg_get_ruledef default args in
system_functions.sql
Modernize pg_get_ruledef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument.
---
src/backend/catalog/system_functions.sql | 7 +++++++
src/backend/utils/adt/ruleutils.c | 18 ------------------
src/include/catalog/pg_proc.dat | 5 +----
3 files changed, 8 insertions(+), 22 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 2d946d6d9e9..febed53c9fa 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -657,6 +657,13 @@ LANGUAGE INTERNAL
STRICT VOLATILE PARALLEL UNSAFE
AS 'pg_replication_origin_session_setup';
+CREATE OR REPLACE FUNCTION
+ pg_get_ruledef(rule oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL SAFE
+AS 'pg_get_ruledef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 556ab057e5a..de063d63b4f 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -558,24 +558,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 5cf9e12fcb9..c215d47f2d8 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,9 +3952,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',
@@ -8492,7 +8489,7 @@
# 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', 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.51.2
From f27d37a1689f2060c50d59ce1043e2710433c5c8 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 09:33:21 -0800
Subject: [PATCH v1 2/6] Handle pg_get_viewdef default args in
system_functions.sql
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index febed53c9fa..c7adfad0e05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index de063d63b4f..7d576834d5c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,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);
@@ -716,31 +697,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 c215d47f2d8..2d1aa50dac6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,13 +3952,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' },
@@ -8494,12 +8487,12 @@
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' },
+ 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' },
+ 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.51.2
From 9c5f218eaa85c05e173919582d431f166c9c9bdb Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 10:02:15 -0800
Subject: [PATCH v1 3/6] Handle pg_get_indexdef default args in
system_functions.sql
Modernize pg_get_indexdef to use CREATE OR REPLACE FUNCTION to handle
the optional column and pretty argument.
---
src/backend/catalog/system_functions.sql | 7 +++++++
src/backend/utils/adt/ruleutils.c | 20 --------------------
src/include/catalog/pg_proc.dat | 5 +----
3 files changed, 8 insertions(+), 24 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index c7adfad0e05..f7b9d26089a 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -678,6 +678,13 @@ LANGUAGE INTERNAL
PARALLEL RESTRICTED
AS 'pg_get_viewdef';
+CREATE OR REPLACE FUNCTION
+ pg_get_indexdef(view oid, "column" int DEFAULT 0, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL SAFE
+AS 'pg_get_indexdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 7d576834d5c..92e2f987074 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -1114,26 +1114,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 2d1aa50dac6..62b997a1653 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3955,9 +3955,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',
@@ -8501,7 +8498,7 @@
{ 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', 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.51.2
From b8595b568acfafede830d1b9d9d1cbfee8c6612f Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 10:59:41 -0800
Subject: [PATCH v1 4/6] Handle pg_get_constraintdef default args in
system_functions.sql
Modernize pg_get_constraintdef to use CREATE OR REPLACE FUNCTION to
handle the optional pretty argument.
---
src/backend/catalog/system_functions.sql | 7 +++++++
src/backend/utils/adt/ruleutils.c | 17 -----------------
src/include/catalog/pg_proc.dat | 5 +----
3 files changed, 8 insertions(+), 21 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index f7b9d26089a..1f89dcc7908 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -685,6 +685,13 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_indexdef';
+CREATE OR REPLACE FUNCTION
+ pg_get_constraintdef("constraint" oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL SAFE
+AS 'pg_get_constraintdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 92e2f987074..416144c49f5 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -2061,23 +2061,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 62b997a1653..a9431ea4037 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3977,9 +3977,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' },
@@ -8501,7 +8498,7 @@
proargtypes => 'oid int4 bool', 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', prosrc => 'pg_get_constraintdef' },
{ oid => '2509',
descr => 'deparse an encoded expression with pretty-print option',
proname => 'pg_get_expr', provolatile => 's', prorettype => 'text',
--
2.51.2
From fff7def908696f9147a62a1cd365abbad63c2e4a Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 11:17:56 -0800
Subject: [PATCH v1 5/6] Handle pg_get_expr default args in
system_functions.sql
Modernize pg_get_expr to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument.
---
src/backend/catalog/system_functions.sql | 7 +++++++
src/backend/utils/adt/ruleutils.c | 17 -----------------
src/include/catalog/pg_proc.dat | 5 +----
3 files changed, 8 insertions(+), 21 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 1f89dcc7908..81d210a9c45 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -692,6 +692,13 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_constraintdef';
+CREATE OR REPLACE FUNCTION
+ pg_get_expr(expr pg_node_tree, relation oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL SAFE
+AS 'pg_get_expr';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 416144c49f5..9effa02fa2e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -2573,23 +2573,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 a9431ea4037..10c5286bd7d 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3977,9 +3977,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' },
@@ -8502,7 +8499,7 @@
{ 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', 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.51.2
From 37e5e8017acf5d2ac5789cea4e13c08bf771b5d2 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 11:51:39 -0800
Subject: [PATCH v1 6/6] Handle pg_get_triggerdef default args in
system_functions.sql
Modernize pg_get_triggerdef to use CREATE OR REPLACE FUNCTION to handle
the optional pretty argument.
---
src/backend/catalog/system_functions.sql | 7 +++++++
src/backend/utils/adt/ruleutils.c | 14 --------------
src/include/catalog/pg_proc.dat | 5 +----
3 files changed, 8 insertions(+), 18 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 81d210a9c45..c9c011ea5c1 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -699,6 +699,13 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_expr';
+CREATE OR REPLACE FUNCTION
+ pg_get_triggerdef(trigger oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL SAFE
+AS 'pg_get_triggerdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 9effa02fa2e..45a35f823e8 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -807,20 +807,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 10c5286bd7d..146963c254b 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3974,9 +3974,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' },
@@ -8535,7 +8532,7 @@
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', prosrc => 'pg_get_triggerdef' },
# asynchronous notifications
{ oid => '3035',
--
2.51.2
Attachments:
[text/plain] v1-0001-Handle-pg_get_ruledef-default-args-in-system_func.patch (3.0K, ../../aTiwu9o8vBkLreAL@ltdrgnflg2/2-v1-0001-Handle-pg_get_ruledef-default-args-in-system_func.patch)
download | inline diff:
From 90229923b475af0169be5cea8819e71425b6a332 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Mon, 8 Dec 2025 15:41:07 -0800
Subject: [PATCH v1 1/6] Handle pg_get_ruledef default args in
system_functions.sql
Modernize pg_get_ruledef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument.
---
src/backend/catalog/system_functions.sql | 7 +++++++
src/backend/utils/adt/ruleutils.c | 18 ------------------
src/include/catalog/pg_proc.dat | 5 +----
3 files changed, 8 insertions(+), 22 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 2d946d6d9e9..febed53c9fa 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -657,6 +657,13 @@ LANGUAGE INTERNAL
STRICT VOLATILE PARALLEL UNSAFE
AS 'pg_replication_origin_session_setup';
+CREATE OR REPLACE FUNCTION
+ pg_get_ruledef(rule oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL SAFE
+AS 'pg_get_ruledef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 556ab057e5a..de063d63b4f 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -558,24 +558,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 5cf9e12fcb9..c215d47f2d8 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,9 +3952,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',
@@ -8492,7 +8489,7 @@
# 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', 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.51.2
[text/plain] v1-0002-Handle-pg_get_viewdef-default-args-in-system_func.patch (4.5K, ../../aTiwu9o8vBkLreAL@ltdrgnflg2/3-v1-0002-Handle-pg_get_viewdef-default-args-in-system_func.patch)
download | inline diff:
From f27d37a1689f2060c50d59ce1043e2710433c5c8 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 09:33:21 -0800
Subject: [PATCH v1 2/6] Handle pg_get_viewdef default args in
system_functions.sql
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index febed53c9fa..c7adfad0e05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index de063d63b4f..7d576834d5c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,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);
@@ -716,31 +697,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 c215d47f2d8..2d1aa50dac6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,13 +3952,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' },
@@ -8494,12 +8487,12 @@
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' },
+ 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' },
+ 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.51.2
[text/plain] v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch (3.3K, ../../aTiwu9o8vBkLreAL@ltdrgnflg2/4-v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch)
download | inline diff:
From 9c5f218eaa85c05e173919582d431f166c9c9bdb Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 10:02:15 -0800
Subject: [PATCH v1 3/6] Handle pg_get_indexdef default args in
system_functions.sql
Modernize pg_get_indexdef to use CREATE OR REPLACE FUNCTION to handle
the optional column and pretty argument.
---
src/backend/catalog/system_functions.sql | 7 +++++++
src/backend/utils/adt/ruleutils.c | 20 --------------------
src/include/catalog/pg_proc.dat | 5 +----
3 files changed, 8 insertions(+), 24 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index c7adfad0e05..f7b9d26089a 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -678,6 +678,13 @@ LANGUAGE INTERNAL
PARALLEL RESTRICTED
AS 'pg_get_viewdef';
+CREATE OR REPLACE FUNCTION
+ pg_get_indexdef(view oid, "column" int DEFAULT 0, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL SAFE
+AS 'pg_get_indexdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 7d576834d5c..92e2f987074 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -1114,26 +1114,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 2d1aa50dac6..62b997a1653 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3955,9 +3955,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',
@@ -8501,7 +8498,7 @@
{ 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', 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.51.2
[text/plain] v1-0004-Handle-pg_get_constraintdef-default-args-in-syste.patch (3.2K, ../../aTiwu9o8vBkLreAL@ltdrgnflg2/5-v1-0004-Handle-pg_get_constraintdef-default-args-in-syste.patch)
download | inline diff:
From b8595b568acfafede830d1b9d9d1cbfee8c6612f Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 10:59:41 -0800
Subject: [PATCH v1 4/6] Handle pg_get_constraintdef default args in
system_functions.sql
Modernize pg_get_constraintdef to use CREATE OR REPLACE FUNCTION to
handle the optional pretty argument.
---
src/backend/catalog/system_functions.sql | 7 +++++++
src/backend/utils/adt/ruleutils.c | 17 -----------------
src/include/catalog/pg_proc.dat | 5 +----
3 files changed, 8 insertions(+), 21 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index f7b9d26089a..1f89dcc7908 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -685,6 +685,13 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_indexdef';
+CREATE OR REPLACE FUNCTION
+ pg_get_constraintdef("constraint" oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL SAFE
+AS 'pg_get_constraintdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 92e2f987074..416144c49f5 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -2061,23 +2061,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 62b997a1653..a9431ea4037 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3977,9 +3977,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' },
@@ -8501,7 +8498,7 @@
proargtypes => 'oid int4 bool', 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', prosrc => 'pg_get_constraintdef' },
{ oid => '2509',
descr => 'deparse an encoded expression with pretty-print option',
proname => 'pg_get_expr', provolatile => 's', prorettype => 'text',
--
2.51.2
[text/plain] v1-0005-Handle-pg_get_expr-default-args-in-system_functio.patch (3.2K, ../../aTiwu9o8vBkLreAL@ltdrgnflg2/6-v1-0005-Handle-pg_get_expr-default-args-in-system_functio.patch)
download | inline diff:
From fff7def908696f9147a62a1cd365abbad63c2e4a Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 11:17:56 -0800
Subject: [PATCH v1 5/6] Handle pg_get_expr default args in
system_functions.sql
Modernize pg_get_expr to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument.
---
src/backend/catalog/system_functions.sql | 7 +++++++
src/backend/utils/adt/ruleutils.c | 17 -----------------
src/include/catalog/pg_proc.dat | 5 +----
3 files changed, 8 insertions(+), 21 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 1f89dcc7908..81d210a9c45 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -692,6 +692,13 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_constraintdef';
+CREATE OR REPLACE FUNCTION
+ pg_get_expr(expr pg_node_tree, relation oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL SAFE
+AS 'pg_get_expr';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 416144c49f5..9effa02fa2e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -2573,23 +2573,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 a9431ea4037..10c5286bd7d 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3977,9 +3977,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' },
@@ -8502,7 +8499,7 @@
{ 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', 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.51.2
[text/plain] v1-0006-Handle-pg_get_triggerdef-default-args-in-system_f.patch (3.0K, ../../aTiwu9o8vBkLreAL@ltdrgnflg2/7-v1-0006-Handle-pg_get_triggerdef-default-args-in-system_f.patch)
download | inline diff:
From 37e5e8017acf5d2ac5789cea4e13c08bf771b5d2 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 11:51:39 -0800
Subject: [PATCH v1 6/6] Handle pg_get_triggerdef default args in
system_functions.sql
Modernize pg_get_triggerdef to use CREATE OR REPLACE FUNCTION to handle
the optional pretty argument.
---
src/backend/catalog/system_functions.sql | 7 +++++++
src/backend/utils/adt/ruleutils.c | 14 --------------
src/include/catalog/pg_proc.dat | 5 +----
3 files changed, 8 insertions(+), 18 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 81d210a9c45..c9c011ea5c1 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -699,6 +699,13 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_expr';
+CREATE OR REPLACE FUNCTION
+ pg_get_triggerdef(trigger oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL SAFE
+AS 'pg_get_triggerdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 9effa02fa2e..45a35f823e8 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -807,20 +807,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 10c5286bd7d..146963c254b 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3974,9 +3974,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' },
@@ -8535,7 +8532,7 @@
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', prosrc => 'pg_get_triggerdef' },
# asynchronous notifications
{ oid => '3035',
--
2.51.2
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: updates for handling optional argument in system functions
2025-12-09 23:28 updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
@ 2025-12-10 09:33 ` Daniel Gustafsson <daniel@yesql.se>
2 siblings, 0 replies; 31+ messages in thread
From: Daniel Gustafsson @ 2025-12-10 09:33 UTC (permalink / raw)
To: Mark Wong <markwkm@gmail.com>; +Cc: Pgsql Hackers <pgsql-hackers@lists.postgresql.org>
> On 10 Dec 2025, at 00:28, Mark Wong <markwkm@gmail.com> wrote:
> Is that something we want?
I have yet to study the patch, but conceptually I am favour of this. I find
reading the code is easier when it's done this way.
--
Daniel Gustafsson
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: updates for handling optional argument in system functions
2025-12-09 23:28 updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
@ 2026-01-20 18:15 ` Mark Wong <markwkm@gmail.com>
2026-01-21 08:45 ` Re: updates for handling optional argument in system functions Chao Li <li.evan.chao@gmail.com>
2 siblings, 1 reply; 31+ messages in thread
From: Mark Wong @ 2026-01-20 18:15 UTC (permalink / raw)
To: pgsql-hackers@lists.postgresql.org
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
--
Mark Wong <markwkm@gmail.com>
EDB https://enterprisedb.com
Attachments:
[text/x-diff] v2-0001-Handle-pg_get_ruledef-default-args-in-system_func.patch (3.0K, ../../aW_GMVYZqGnebYLE@o/2-v2-0001-Handle-pg_get_ruledef-default-args-in-system_func.patch)
download | inline diff:
From 9473f136a96fb3d6fc87e5390c6609fa8dfd446a Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Mon, 8 Dec 2025 15:41:07 -0800
Subject: [PATCH v2 1/6] Handle pg_get_ruledef default args in
system_functions.sql
Modernize pg_get_ruledef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument.
---
src/backend/catalog/system_functions.sql | 7 +++++++
src/backend/utils/adt/ruleutils.c | 18 ------------------
src/include/catalog/pg_proc.dat | 5 +----
3 files changed, 8 insertions(+), 22 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index eb9e31ae1bf..3aad2fbf8f3 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -657,6 +657,13 @@ LANGUAGE INTERNAL
STRICT VOLATILE PARALLEL UNSAFE
AS 'pg_replication_origin_session_setup';
+CREATE OR REPLACE FUNCTION
+ pg_get_ruledef(rule oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL SAFE
+AS 'pg_get_ruledef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 416f1a21ae4..c4d424ba10d 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -558,24 +558,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 2ac69bf2df5..597c468983e 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,9 +3961,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',
@@ -8508,7 +8505,7 @@
# 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', 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
[text/x-diff] v2-0002-Handle-pg_get_viewdef-default-args-in-system_func.patch (4.5K, ../../aW_GMVYZqGnebYLE@o/3-v2-0002-Handle-pg_get_viewdef-default-args-in-system_func.patch)
download | inline diff:
From b6a8af24cc070a3ca7ce25bc8819c756840408ac Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 09:33:21 -0800
Subject: [PATCH v2 2/6] Handle pg_get_viewdef default args in
system_functions.sql
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c4d424ba10d..57b4adc0e2a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,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);
@@ -716,31 +697,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 597c468983e..9b87b9eda5f 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,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' },
@@ -8510,12 +8503,12 @@
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' },
+ 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' },
+ 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
[text/x-diff] v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch (3.3K, ../../aW_GMVYZqGnebYLE@o/4-v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch)
download | inline diff:
From 42def2bf5903e87bf41c2bda622ce8d5086f3f2d Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 10:02:15 -0800
Subject: [PATCH v2 3/6] Handle pg_get_indexdef default args in
system_functions.sql
Modernize pg_get_indexdef to use CREATE OR REPLACE FUNCTION to handle
the optional column and pretty argument.
---
src/backend/catalog/system_functions.sql | 7 +++++++
src/backend/utils/adt/ruleutils.c | 20 --------------------
src/include/catalog/pg_proc.dat | 5 +----
3 files changed, 8 insertions(+), 24 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 4ddbf194fa8..72f5fdc06f9 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -678,6 +678,13 @@ LANGUAGE INTERNAL
PARALLEL RESTRICTED
AS 'pg_get_viewdef';
+CREATE OR REPLACE FUNCTION
+ pg_get_indexdef(view oid, "column" int DEFAULT 0, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL SAFE
+AS 'pg_get_indexdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 57b4adc0e2a..bb5863212cd 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -1114,26 +1114,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 9b87b9eda5f..56f68cee830 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3964,9 +3964,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',
@@ -8517,7 +8514,7 @@
{ 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', 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
[text/x-diff] v2-0004-Handle-pg_get_constraintdef-default-args-in-syste.patch (3.2K, ../../aW_GMVYZqGnebYLE@o/5-v2-0004-Handle-pg_get_constraintdef-default-args-in-syste.patch)
download | inline diff:
From b20d23ebc2041cd8d930e490f2de0c75ebb0773e Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 10:59:41 -0800
Subject: [PATCH v2 4/6] Handle pg_get_constraintdef default args in
system_functions.sql
Modernize pg_get_constraintdef to use CREATE OR REPLACE FUNCTION to
handle the optional pretty argument.
---
src/backend/catalog/system_functions.sql | 7 +++++++
src/backend/utils/adt/ruleutils.c | 17 -----------------
src/include/catalog/pg_proc.dat | 5 +----
3 files changed, 8 insertions(+), 21 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 72f5fdc06f9..1824faab231 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -685,6 +685,13 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_indexdef';
+CREATE OR REPLACE FUNCTION
+ pg_get_constraintdef("constraint" oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL SAFE
+AS 'pg_get_constraintdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index bb5863212cd..9faf340f0c6 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -2061,23 +2061,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 56f68cee830..96eb7baf8e0 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3986,9 +3986,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' },
@@ -8517,7 +8514,7 @@
proargtypes => 'oid int4 bool', 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', 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
[text/x-diff] v2-0005-Handle-pg_get_expr-default-args-in-system_functio.patch (3.8K, ../../aW_GMVYZqGnebYLE@o/6-v2-0005-Handle-pg_get_expr-default-args-in-system_functio.patch)
download | inline diff:
From 8c35048d28b6f3760b7085bf321fd961557e0d42 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 11:17:56 -0800
Subject: [PATCH v2 5/6] Handle pg_get_expr default args in
system_functions.sql
Modernize pg_get_expr to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument.
---
src/backend/catalog/system_functions.sql | 7 +++++++
src/backend/commands/tablecmds.c | 4 ++--
src/backend/utils/adt/ruleutils.c | 17 -----------------
src/include/catalog/pg_proc.dat | 5 +----
4 files changed, 10 insertions(+), 23 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 1824faab231..a6f7cdf3a36 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -692,6 +692,13 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_constraintdef';
+CREATE OR REPLACE FUNCTION
+ pg_get_expr(expr pg_node_tree, relation oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL SAFE
+AS 'pg_get_expr';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index f976c0e5c7e..12c4ce08437 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -17480,8 +17480,8 @@ 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), false);
return TextDatumGetCString(expr);
}
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 9faf340f0c6..305e3e80c41 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -2573,23 +2573,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 96eb7baf8e0..3a0be2d4b2a 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3986,9 +3986,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' },
@@ -8518,7 +8515,7 @@
{ 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', 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
[text/x-diff] v2-0006-Handle-pg_get_triggerdef-default-args-in-system_f.patch (3.0K, ../../aW_GMVYZqGnebYLE@o/7-v2-0006-Handle-pg_get_triggerdef-default-args-in-system_f.patch)
download | inline diff:
From 2efa70b7cdbd2e6efa35c2d4e7c242ac974b902b Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 11:51:39 -0800
Subject: [PATCH v2 6/6] Handle pg_get_triggerdef default args in
system_functions.sql
Modernize pg_get_triggerdef to use CREATE OR REPLACE FUNCTION to handle
the optional pretty argument.
---
src/backend/catalog/system_functions.sql | 7 +++++++
src/backend/utils/adt/ruleutils.c | 14 --------------
src/include/catalog/pg_proc.dat | 5 +----
3 files changed, 8 insertions(+), 18 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index a6f7cdf3a36..08b9b68d0cd 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -699,6 +699,13 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_expr';
+CREATE OR REPLACE FUNCTION
+ pg_get_triggerdef(trigger oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL SAFE
+AS 'pg_get_triggerdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 305e3e80c41..188d367b113 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -807,20 +807,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 3a0be2d4b2a..d644a391e0e 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3983,9 +3983,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' },
@@ -8551,7 +8548,7 @@
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', prosrc => 'pg_get_triggerdef' },
# asynchronous notifications
{ oid => '3035',
--
2.43.0
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: updates for handling optional argument in system functions
2025-12-09 23:28 updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-01-20 18:15 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
@ 2026-01-21 08:45 ` Chao Li <li.evan.chao@gmail.com>
2026-01-30 00:15 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
0 siblings, 1 reply; 31+ messages in thread
From: Chao Li @ 2026-01-21 08:45 UTC (permalink / raw)
To: Mark Wong <markwkm@gmail.com>; +Cc: pgsql-hackers@lists.postgresql.org
> On Jan 21, 2026, at 02:15, Mark Wong <markwkm@gmail.com> 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
> --
> Mark Wong <markwkm@gmail.com>
> EDB https://enterprisedb.com
> <v2-0001-Handle-pg_get_ruledef-default-args-in-system_func.patch><v2-0002-Handle-pg_get_viewdef-default-args-in-system_func.patch><v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch><v2-0004-Handle-pg_get_constraintdef-default-args-in-syste.patch><v2-0005-Handle-pg_get_expr-default-args-in-system_functio.patch><v2-0006-Handle-pg_get_triggerdef-default-args-in-system_f.patch>
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?
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: updates for handling optional argument in system functions
2025-12-09 23:28 updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-01-20 18:15 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-01-21 08:45 ` Re: updates for handling optional argument in system functions Chao Li <li.evan.chao@gmail.com>
@ 2026-01-30 00:15 ` Mark Wong <markwkm@gmail.com>
2026-02-18 21:56 ` Re: updates for handling optional argument in system functions Andreas Karlsson <andreas@proxel.se>
2026-03-03 16:23 ` Re: updates for handling optional argument in system functions Álvaro Herrera <alvherre@kurilemu.de>
0 siblings, 2 replies; 31+ messages in thread
From: Mark Wong @ 2026-01-30 00:15 UTC (permalink / raw)
To: Chao Li <li.evan.chao@gmail.com>; +Cc: pgsql-hackers@lists.postgresql.org
On Wed, Jan 21, 2026 at 04:45:35PM +0800, Chao Li wrote:
>
>
> > On Jan 21, 2026, at 02:15, Mark Wong <markwkm@gmail.com> 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 <markwkm@gmail.com>
EDB https://enterprisedb.com
Attachments:
[text/x-diff] v3-0001-Track-retired-system-procedures-in-pg_retired.dat.patch (3.0K, ../../aXv4FjR1RTr386D1@o/2-v3-0001-Track-retired-system-procedures-in-pg_retired.dat.patch)
download | inline diff:
From 51b5d084bb6065a5d908a4e71fd4dcedf0d2f993 Mon Sep 17 00:00:00 2001
From: Mark Wong <mark.wong@enterprisedb.com>
Date: Thu, 29 Jan 2026 15:47:50 -0800
Subject: [PATCH v3 1/7] Track retired system procedures in pg_retired.dat
System procedures may be removed from time to time. Keep track of
previously used OIDs to prevent potential conflicts from reusing OIDs
after an upgrade.
---
src/include/catalog/pg_retired.dat | 20 ++++++++++++++++++++
src/include/catalog/renumber_oids.pl | 9 +++++++++
src/include/catalog/unused_oids | 7 +++++++
3 files changed, 36 insertions(+)
create mode 100644 src/include/catalog/pg_retired.dat
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
new file mode 100644
index 00000000000..413b68ad1cd
--- /dev/null
+++ b/src/include/catalog/pg_retired.dat
@@ -0,0 +1,20 @@
+#----------------------------------------------------------------------
+#
+# pg_retired.dat
+# Entries that have been removed from pg_proc.dat with OIDs that are
+# are not to be reused.
+#
+# Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
+# Portions Copyright (c) 1994, Regents of the University of California
+#
+# src/include/catalog/pg_retired.dat
+#
+#----------------------------------------------------------------------
+
+[
+
+# What's primarily important here is knowing which OIDs are not to be reused.
+# At the same time, it may be good to be reminded what procedure was associated
+# with it.
+
+]
diff --git a/src/include/catalog/renumber_oids.pl b/src/include/catalog/renumber_oids.pl
index f6e25d0f1e1..7489be02a50 100755
--- a/src/include/catalog/renumber_oids.pl
+++ b/src/include/catalog/renumber_oids.pl
@@ -68,6 +68,15 @@ my $oids = Catalog::FindAllOidsFromHeaders(@header_files);
my %oidhash;
@oidhash{@$oids} = undef;
+# Also include OIDs listed in pg_retired.dat to prevent new OIDs to be mapped
+# to OIDs that have been retired.
+my $retired_data = Catalog::ParseData('pg_retired.dat', undef, 0);
+foreach my $row (@$retired_data)
+{
+ $oidhash{ $row->{oid} } = undef
+ if ref $row eq 'HASH' && defined $row->{oid};
+}
+
# Select new OIDs for existing OIDs in the mapped range.
# We do this first so that we preserve the ordering of the mapped OIDs
# (for reproducibility's sake), and so that if we fail due to running out
diff --git a/src/include/catalog/unused_oids b/src/include/catalog/unused_oids
index 147fba5e209..aeb485d9b5e 100755
--- a/src/include/catalog/unused_oids
+++ b/src/include/catalog/unused_oids
@@ -32,6 +32,13 @@ my @input_files = glob("pg_*.h");
my $oids = Catalog::FindAllOidsFromHeaders(@input_files);
+# Also exclude OIDs listed in pg_retired.dat
+my $retired_data = Catalog::ParseData('pg_retired.dat', undef, 0);
+foreach my $row (@$retired_data)
+{
+ push @{$oids}, $row->{oid} if ref $row eq 'HASH' && defined $row->{oid};
+}
+
# Also push FirstGenbkiObjectId to serve as a terminator for the last gap.
my $FirstGenbkiObjectId =
Catalog::FindDefinedSymbol('access/transam.h', '..', 'FirstGenbkiObjectId');
--
2.43.0
[text/x-diff] v3-0002-Handle-pg_get_ruledef-default-args-in-system_func.patch (3.5K, ../../aXv4FjR1RTr386D1@o/3-v3-0002-Handle-pg_get_ruledef-default-args-in-system_func.patch)
download | inline diff:
From b1173574478c61d6001da5c6caf8b6052dde20ad Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Mon, 8 Dec 2025 15:41:07 -0800
Subject: [PATCH v3 2/7] Handle pg_get_ruledef default args in
system_functions.sql
Modernize pg_get_ruledef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument.
---
src/backend/catalog/system_functions.sql | 7 +++++++
src/backend/utils/adt/ruleutils.c | 18 ------------------
src/include/catalog/pg_proc.dat | 5 +----
src/include/catalog/pg_retired.dat | 2 ++
4 files changed, 10 insertions(+), 22 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index eb9e31ae1bf..3aad2fbf8f3 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -657,6 +657,13 @@ LANGUAGE INTERNAL
STRICT VOLATILE PARALLEL UNSAFE
AS 'pg_replication_origin_session_setup';
+CREATE OR REPLACE FUNCTION
+ pg_get_ruledef(rule oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL SAFE
+AS 'pg_get_ruledef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 033b625f3fc..3733212fe0a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -558,24 +558,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 894b6a1b6d6..2a3362567a7 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,9 +3961,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',
@@ -8508,7 +8505,7 @@
# 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', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index 413b68ad1cd..a3ce10c7f62 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,4 +17,6 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
+{ oid => '1573', proname => 'pg_get_ruledef' }
+
]
--
2.43.0
[text/x-diff] v3-0003-Handle-pg_get_viewdef-default-args-in-system_func.patch (5.0K, ../../aXv4FjR1RTr386D1@o/4-v3-0003-Handle-pg_get_viewdef-default-args-in-system_func.patch)
download | inline diff:
From ced739f304da4dc36f5b57120bf5cd9adb55ffc2 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 09:33:21 -0800
Subject: [PATCH v3 3/7] Handle pg_get_viewdef default args in
system_functions.sql
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
src/include/catalog/pg_retired.dat | 4 ++-
4 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 3733212fe0a..29557f3c9d2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,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);
@@ -716,31 +697,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 2a3362567a7..531d0dea7db 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,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' },
@@ -8510,12 +8503,12 @@
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' },
+ 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' },
+ 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',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index a3ce10c7f62..d5d51ddb3e8 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,6 +17,8 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
-{ oid => '1573', proname => 'pg_get_ruledef' }
+{ oid => '1573', proname => 'pg_get_ruledef' },
+{ oid => '1640', proname => 'pg_get_viewdef' },
+{ oid => '1641', proname => 'pg_get_viewdef' }
]
--
2.43.0
[text/x-diff] v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch (3.8K, ../../aXv4FjR1RTr386D1@o/5-v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch)
download | inline diff:
From 9387c816f2b19f6317106b7e1151262b4506c259 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 10:02:15 -0800
Subject: [PATCH v3 4/7] Handle pg_get_indexdef default args in
system_functions.sql
Modernize pg_get_indexdef to use CREATE OR REPLACE FUNCTION to handle
the optional column and pretty argument.
---
src/backend/catalog/system_functions.sql | 7 +++++++
src/backend/utils/adt/ruleutils.c | 20 --------------------
src/include/catalog/pg_proc.dat | 5 +----
src/include/catalog/pg_retired.dat | 3 ++-
4 files changed, 10 insertions(+), 25 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 4ddbf194fa8..72f5fdc06f9 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -678,6 +678,13 @@ LANGUAGE INTERNAL
PARALLEL RESTRICTED
AS 'pg_get_viewdef';
+CREATE OR REPLACE FUNCTION
+ pg_get_indexdef(view oid, "column" int DEFAULT 0, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL SAFE
+AS 'pg_get_indexdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 29557f3c9d2..d8b8d7b4d38 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -1114,26 +1114,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 531d0dea7db..fee5efca41e 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3964,9 +3964,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',
@@ -8517,7 +8514,7 @@
{ 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', 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' },
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index d5d51ddb3e8..768ce980a1d 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -19,6 +19,7 @@
{ oid => '1573', proname => 'pg_get_ruledef' },
{ oid => '1640', proname => 'pg_get_viewdef' },
-{ oid => '1641', proname => 'pg_get_viewdef' }
+{ oid => '1641', proname => 'pg_get_viewdef' },
+{ oid => '1643', proname => 'pg_get_indexdef' }
]
--
2.43.0
[text/x-diff] v3-0005-Handle-pg_get_constraintdef-default-args-in-syste.patch (3.8K, ../../aXv4FjR1RTr386D1@o/6-v3-0005-Handle-pg_get_constraintdef-default-args-in-syste.patch)
download | inline diff:
From 7f4b48ef95c61bb3a82e54a8d1981c82879f91f8 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 10:59:41 -0800
Subject: [PATCH v3 5/7] Handle pg_get_constraintdef default args in
system_functions.sql
Modernize pg_get_constraintdef to use CREATE OR REPLACE FUNCTION to
handle the optional pretty argument.
---
src/backend/catalog/system_functions.sql | 7 +++++++
src/backend/utils/adt/ruleutils.c | 17 -----------------
src/include/catalog/pg_proc.dat | 5 +----
src/include/catalog/pg_retired.dat | 1 +
4 files changed, 9 insertions(+), 21 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 72f5fdc06f9..1824faab231 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -685,6 +685,13 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_indexdef';
+CREATE OR REPLACE FUNCTION
+ pg_get_constraintdef("constraint" oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL SAFE
+AS 'pg_get_constraintdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index d8b8d7b4d38..4f2c93f1ee2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -2061,23 +2061,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 fee5efca41e..ffec11c5539 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3986,9 +3986,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' },
@@ -8517,7 +8514,7 @@
proargtypes => 'oid int4 bool', 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', prosrc => 'pg_get_constraintdef' },
{ oid => '2509',
descr => 'deparse an encoded expression with pretty-print option',
proname => 'pg_get_expr', provolatile => 's', prorettype => 'text',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index 768ce980a1d..90928a9cb00 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,6 +17,7 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
+{ oid => '1387', proname => 'pg_get_constraintdef' },
{ oid => '1573', proname => 'pg_get_ruledef' },
{ oid => '1640', proname => 'pg_get_viewdef' },
{ oid => '1641', proname => 'pg_get_viewdef' },
--
2.43.0
[text/x-diff] v3-0006-Handle-pg_get_expr-default-args-in-system_functio.patch (4.4K, ../../aXv4FjR1RTr386D1@o/7-v3-0006-Handle-pg_get_expr-default-args-in-system_functio.patch)
download | inline diff:
From 334e0e4d4834800c824304d67e7a88fdd6c43b94 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 11:17:56 -0800
Subject: [PATCH v3 6/7] Handle pg_get_expr default args in
system_functions.sql
Modernize pg_get_expr to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument.
---
src/backend/catalog/system_functions.sql | 7 +++++++
src/backend/commands/tablecmds.c | 4 ++--
src/backend/utils/adt/ruleutils.c | 17 -----------------
src/include/catalog/pg_proc.dat | 5 +----
src/include/catalog/pg_retired.dat | 3 ++-
5 files changed, 12 insertions(+), 24 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 1824faab231..a6f7cdf3a36 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -692,6 +692,13 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_constraintdef';
+CREATE OR REPLACE FUNCTION
+ pg_get_expr(expr pg_node_tree, relation oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL SAFE
+AS 'pg_get_expr';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index f976c0e5c7e..12c4ce08437 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -17480,8 +17480,8 @@ 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), false);
return TextDatumGetCString(expr);
}
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 4f2c93f1ee2..d87b361a093 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -2573,23 +2573,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 ffec11c5539..4304ab220ba 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3986,9 +3986,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' },
@@ -8518,7 +8515,7 @@
{ 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', 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',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index 90928a9cb00..8b5f58850f6 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -21,6 +21,7 @@
{ oid => '1573', proname => 'pg_get_ruledef' },
{ oid => '1640', proname => 'pg_get_viewdef' },
{ oid => '1641', proname => 'pg_get_viewdef' },
-{ oid => '1643', proname => 'pg_get_indexdef' }
+{ oid => '1643', proname => 'pg_get_indexdef' },
+{ oid => '1716', proname => 'pg_get_expr' }
]
--
2.43.0
[text/x-diff] v3-0007-Handle-pg_get_triggerdef-default-args-in-system_f.patch (3.5K, ../../aXv4FjR1RTr386D1@o/8-v3-0007-Handle-pg_get_triggerdef-default-args-in-system_f.patch)
download | inline diff:
From 0b96cf0a17fec1be6cb0afd40b1bd03d7cadc4a6 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 11:51:39 -0800
Subject: [PATCH v3 7/7] Handle pg_get_triggerdef default args in
system_functions.sql
Modernize pg_get_triggerdef to use CREATE OR REPLACE FUNCTION to handle
the optional pretty argument.
---
src/backend/catalog/system_functions.sql | 7 +++++++
src/backend/utils/adt/ruleutils.c | 14 --------------
src/include/catalog/pg_proc.dat | 5 +----
src/include/catalog/pg_retired.dat | 1 +
4 files changed, 9 insertions(+), 18 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index a6f7cdf3a36..08b9b68d0cd 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -699,6 +699,13 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_expr';
+CREATE OR REPLACE FUNCTION
+ pg_get_triggerdef(trigger oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL SAFE
+AS 'pg_get_triggerdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index d87b361a093..598c916ddb6 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -807,20 +807,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 4304ab220ba..bf00983b3ff 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3983,9 +3983,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' },
@@ -8551,7 +8548,7 @@
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', prosrc => 'pg_get_triggerdef' },
# asynchronous notifications
{ oid => '3035',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index 8b5f58850f6..46764648040 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -22,6 +22,7 @@
{ oid => '1640', proname => 'pg_get_viewdef' },
{ oid => '1641', proname => 'pg_get_viewdef' },
{ oid => '1643', proname => 'pg_get_indexdef' },
+{ oid => '1662', proname => 'pg_get_triggerdef' },
{ oid => '1716', proname => 'pg_get_expr' }
]
--
2.43.0
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: updates for handling optional argument in system functions
2025-12-09 23:28 updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-01-20 18:15 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-01-21 08:45 ` Re: updates for handling optional argument in system functions Chao Li <li.evan.chao@gmail.com>
2026-01-30 00:15 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
@ 2026-02-18 21:56 ` Andreas Karlsson <andreas@proxel.se>
2026-02-26 19:43 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
1 sibling, 1 reply; 31+ messages in thread
From: Andreas Karlsson @ 2026-02-18 21:56 UTC (permalink / raw)
To: Mark Wong <markwkm@gmail.com>; Chao Li <li.evan.chao@gmail.com>; +Cc: pgsql-hackers@lists.postgresql.org
On 1/30/26 1:15 AM, Mark Wong wrote:
>> 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...
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
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: updates for handling optional argument in system functions
2025-12-09 23:28 updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-01-20 18:15 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-01-21 08:45 ` Re: updates for handling optional argument in system functions Chao Li <li.evan.chao@gmail.com>
2026-01-30 00:15 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-02-18 21:56 ` Re: updates for handling optional argument in system functions Andreas Karlsson <andreas@proxel.se>
@ 2026-02-26 19:43 ` Mark Wong <markwkm@gmail.com>
0 siblings, 0 replies; 31+ messages in thread
From: Mark Wong @ 2026-02-26 19:43 UTC (permalink / raw)
To: Andreas Karlsson <andreas@proxel.se>; +Cc: Chao Li <li.evan.chao@gmail.com>; pgsql-hackers@lists.postgresql.org
On Wed, Feb 18, 2026 at 10:56:56PM +0100, Andreas Karlsson wrote:
> On 1/30/26 1:15 AM, Mark Wong wrote:
> > > 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...
> 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
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
--
Mark Wong <markwkm@gmail.com>
EDB https://enterprisedb.com
Attachments:
[text/x-diff] v4-0001-Handle-pg_get_ruledef-default-args-in-system_func.patch (2.4K, ../../aaCiYo2AgSJaP22a@o/2-v4-0001-Handle-pg_get_ruledef-default-args-in-system_func.patch)
download | inline diff:
From fdca206df20d4586f209cbb108761532f0b2935a Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
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
[text/x-diff] v4-0002-Handle-pg_get_viewdef-default-args-in-system_func.patch (3.8K, ../../aaCiYo2AgSJaP22a@o/3-v4-0002-Handle-pg_get_viewdef-default-args-in-system_func.patch)
download | inline diff:
From 13ce84d431a34a78d9715b299d8f9b33b8861290 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
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
[text/x-diff] v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch (2.6K, ../../aaCiYo2AgSJaP22a@o/4-v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch)
download | inline diff:
From e4f7ae2de2a1e0cc131dc35ecf416832e27c6b20 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
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
[text/x-diff] v4-0004-Handle-pg_get_constraintdef-default-args-in-syste.patch (2.6K, ../../aaCiYo2AgSJaP22a@o/5-v4-0004-Handle-pg_get_constraintdef-default-args-in-syste.patch)
download | inline diff:
From 07eac504026eb72bc16afe72bdcee00e3d1d5b26 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
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
[text/x-diff] v4-0005-Handle-pg_get_expr-default-args-in-system_functio.patch (3.3K, ../../aaCiYo2AgSJaP22a@o/6-v4-0005-Handle-pg_get_expr-default-args-in-system_functio.patch)
download | inline diff:
From 49c9382e0ab6a18b687e7fb391b837b8ab33c360 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
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
[text/x-diff] v4-0006-Handle-pg_get_triggerdef-default-args-in-system_f.patch (2.3K, ../../aaCiYo2AgSJaP22a@o/7-v4-0006-Handle-pg_get_triggerdef-default-args-in-system_f.patch)
download | inline diff:
From 8d48c5a3935efb8e50b5b8d51a240336e124e5d1 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
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
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: updates for handling optional argument in system functions
2025-12-09 23:28 updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-01-20 18:15 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-01-21 08:45 ` Re: updates for handling optional argument in system functions Chao Li <li.evan.chao@gmail.com>
2026-01-30 00:15 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
@ 2026-03-03 16:23 ` Álvaro Herrera <alvherre@kurilemu.de>
2026-03-12 03:28 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
1 sibling, 1 reply; 31+ messages in thread
From: Álvaro Herrera @ 2026-03-03 16:23 UTC (permalink / raw)
To: Mark Wong <markwkm@gmail.com>; +Cc: Chao Li <li.evan.chao@gmail.com>; pgsql-hackers@lists.postgresql.org
On 2026-Jan-29, Mark Wong wrote:
> 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.
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?
--
Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/
Syntax error: function hell() needs an argument.
Please choose what hell you want to involve.
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: updates for handling optional argument in system functions
2025-12-09 23:28 updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-01-20 18:15 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-01-21 08:45 ` Re: updates for handling optional argument in system functions Chao Li <li.evan.chao@gmail.com>
2026-01-30 00:15 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-03-03 16:23 ` Re: updates for handling optional argument in system functions Álvaro Herrera <alvherre@kurilemu.de>
@ 2026-03-12 03:28 ` Mark Wong <markwkm@gmail.com>
0 siblings, 0 replies; 31+ messages in thread
From: Mark Wong @ 2026-03-12 03:28 UTC (permalink / raw)
To: Álvaro Herrera <alvherre@kurilemu.de>; +Cc: Chao Li <li.evan.chao@gmail.com>; pgsql-hackers@lists.postgresql.org
On Tue, Mar 03, 2026 at 05:23:58PM +0100, Álvaro Herrera wrote:
> On 2026-Jan-29, Mark Wong wrote:
>
> > 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.
>
> 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
--
Mark Wong <markwkm@gmail.com>
EDB https://enterprisedb.com
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: updates for handling optional argument in system functions
2025-12-09 23:28 updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
@ 2026-04-02 18:36 ` Mark Wong <markwkm@gmail.com>
2026-04-07 22:26 ` Re: updates for handling optional argument in system functions Andreas Karlsson <andreas@proxel.se>
2 siblings, 1 reply; 31+ messages in thread
From: Mark Wong @ 2026-04-02 18:36 UTC (permalink / raw)
To: pgsql-hackers@lists.postgresql.org
Hi everyone,
I've attached v5, simply a needed rebase due to some other churn in
pg_proc.dat.
Regards,
Mark
From 9d458ea4b4296e21ca4cdb76a337a97268db1c12 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Mon, 8 Dec 2025 15:41:07 -0800
Subject: [PATCH v5 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 aec5556b008..99ece0c1761 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -569,24 +569,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 3579cec5744..66cb016792c 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,9 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ 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',
@@ -8580,7 +8577,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.52.0
From 950783c829c7455a223d21437eca1decb68d4d7f Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 09:33:21 -0800
Subject: [PATCH v5 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 99ece0c1761..24c59510672 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,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);
@@ -727,31 +708,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 66cb016792c..c1b945cdae5 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ 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' },
@@ -8583,12 +8576,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.52.0
From a415d62139562939b0c2bf291f120608fdea5e59 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 10:02:15 -0800
Subject: [PATCH v5 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 24c59510672..77a7b0ca769 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -1125,26 +1125,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 c1b945cdae5..1dc0d01cc85 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3978,9 +3978,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',
@@ -8592,7 +8589,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.52.0
From 9e1f6491592d5048df6d23e8b4076f5b55158f4c Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 10:59:41 -0800
Subject: [PATCH v5 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 77a7b0ca769..1afa2531f30 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -2420,23 +2420,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 1dc0d01cc85..e148b1ad8e3 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -4000,9 +4000,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' },
@@ -8593,7 +8590,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.52.0
From 8398495c17b4c62afe8621a373de2fc6f9d25df9 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 11:17:56 -0800
Subject: [PATCH v5 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 0ce2e81f9c2..fad4202b1ff 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -17694,8 +17694,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 1afa2531f30..972f89eafbc 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -2932,23 +2932,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 e148b1ad8e3..f36f4625e50 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -4000,9 +4000,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' },
@@ -8595,7 +8592,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.52.0
From 27d5aa68ab60023a6ecc1845b6152befe2770ac6 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 11:51:39 -0800
Subject: [PATCH v5 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 972f89eafbc..bd0ca6891c3 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -818,20 +818,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 f36f4625e50..43844bb6862 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3997,9 +3997,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' },
@@ -8630,7 +8627,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.52.0
Attachments:
[text/plain] v5-0001-Handle-pg_get_ruledef-default-args-in-system_func.patch (2.5K, ../../ac63G6p1LAdbsca0@ltdrgnflg2/2-v5-0001-Handle-pg_get_ruledef-default-args-in-system_func.patch)
download | inline diff:
From 9d458ea4b4296e21ca4cdb76a337a97268db1c12 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Mon, 8 Dec 2025 15:41:07 -0800
Subject: [PATCH v5 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 aec5556b008..99ece0c1761 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -569,24 +569,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 3579cec5744..66cb016792c 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,9 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ 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',
@@ -8580,7 +8577,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.52.0
[text/plain] v5-0002-Handle-pg_get_viewdef-default-args-in-system_func.patch (3.9K, ../../ac63G6p1LAdbsca0@ltdrgnflg2/3-v5-0002-Handle-pg_get_viewdef-default-args-in-system_func.patch)
download | inline diff:
From 950783c829c7455a223d21437eca1decb68d4d7f Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 09:33:21 -0800
Subject: [PATCH v5 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 99ece0c1761..24c59510672 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,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);
@@ -727,31 +708,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 66cb016792c..c1b945cdae5 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ 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' },
@@ -8583,12 +8576,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.52.0
[text/plain] v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch (2.6K, ../../ac63G6p1LAdbsca0@ltdrgnflg2/4-v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch)
download | inline diff:
From a415d62139562939b0c2bf291f120608fdea5e59 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 10:02:15 -0800
Subject: [PATCH v5 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 24c59510672..77a7b0ca769 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -1125,26 +1125,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 c1b945cdae5..1dc0d01cc85 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3978,9 +3978,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',
@@ -8592,7 +8589,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.52.0
[text/plain] v5-0004-Handle-pg_get_constraintdef-default-args-in-syste.patch (2.6K, ../../ac63G6p1LAdbsca0@ltdrgnflg2/5-v5-0004-Handle-pg_get_constraintdef-default-args-in-syste.patch)
download | inline diff:
From 9e1f6491592d5048df6d23e8b4076f5b55158f4c Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 10:59:41 -0800
Subject: [PATCH v5 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 77a7b0ca769..1afa2531f30 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -2420,23 +2420,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 1dc0d01cc85..e148b1ad8e3 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -4000,9 +4000,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' },
@@ -8593,7 +8590,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.52.0
[text/plain] v5-0005-Handle-pg_get_expr-default-args-in-system_functio.patch (3.3K, ../../ac63G6p1LAdbsca0@ltdrgnflg2/6-v5-0005-Handle-pg_get_expr-default-args-in-system_functio.patch)
download | inline diff:
From 8398495c17b4c62afe8621a373de2fc6f9d25df9 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 11:17:56 -0800
Subject: [PATCH v5 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 0ce2e81f9c2..fad4202b1ff 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -17694,8 +17694,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 1afa2531f30..972f89eafbc 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -2932,23 +2932,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 e148b1ad8e3..f36f4625e50 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -4000,9 +4000,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' },
@@ -8595,7 +8592,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.52.0
[text/plain] v5-0006-Handle-pg_get_triggerdef-default-args-in-system_f.patch (2.3K, ../../ac63G6p1LAdbsca0@ltdrgnflg2/7-v5-0006-Handle-pg_get_triggerdef-default-args-in-system_f.patch)
download | inline diff:
From 27d5aa68ab60023a6ecc1845b6152befe2770ac6 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 11:51:39 -0800
Subject: [PATCH v5 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 972f89eafbc..bd0ca6891c3 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -818,20 +818,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 f36f4625e50..43844bb6862 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3997,9 +3997,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' },
@@ -8630,7 +8627,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.52.0
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: updates for handling optional argument in system functions
2025-12-09 23:28 updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-02 18:36 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
@ 2026-04-07 22:26 ` Andreas Karlsson <andreas@proxel.se>
2026-04-07 23:28 ` Re: updates for handling optional argument in system functions Andreas Karlsson <andreas@proxel.se>
2026-04-07 23:42 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
0 siblings, 2 replies; 31+ messages in thread
From: Andreas Karlsson @ 2026-04-07 22:26 UTC (permalink / raw)
To: Mark Wong <markwkm@gmail.com>; pgsql-hackers@lists.postgresql.org
On 4/2/26 8:36 PM, Mark Wong wrote:
> I've attached v5, simply a needed rebase due to some other churn in
> pg_proc.dat.
Nice, I like the patch. The code changes looks good and I like the
removal of these duplicate functions and use of default arguments. But I
think the names of the arguments should be aligned with the names we
have in the documentation. And that may mean that we should change the
documentation.
For example:
= Code
pg_get_ruledef(rule, pretty)
= Docs
pg_get_ruledef(rule_oid, pretty_bool)
= Should docs maybe be updated to the following?
pg_get_ruledef(rule oid, pretty bool)
--
Andreas Karlsson
Percona
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: updates for handling optional argument in system functions
2025-12-09 23:28 updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-02 18:36 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-07 22:26 ` Re: updates for handling optional argument in system functions Andreas Karlsson <andreas@proxel.se>
@ 2026-04-07 23:28 ` Andreas Karlsson <andreas@proxel.se>
2026-04-07 23:44 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
1 sibling, 1 reply; 31+ messages in thread
From: Andreas Karlsson @ 2026-04-07 23:28 UTC (permalink / raw)
To: Mark Wong <markwkm@gmail.com>; pgsql-hackers@lists.postgresql.org
On 4/8/26 12:26 AM, Andreas Karlsson wrote:
> On 4/2/26 8:36 PM, Mark Wong wrote:
>> I've attached v5, simply a needed rebase due to some other churn in
>> pg_proc.dat.
>
> Nice, I like the patch. The code changes looks good and I like the
> removal of these duplicate functions and use of default arguments. But I
> think the names of the arguments should be aligned with the names we
> have in the documentation. And that may mean that we should change the
> documentation.
Forgot to attach rebased patches.
--
Andreas Karlsson
Percona
Attachments:
[text/x-patch] v6-0001-Handle-pg_get_ruledef-default-args-in-system_func.patch (2.5K, ../../9e3ad0f4-c4ef-436b-a5a1-28f600d76a61@proxel.se/2-v6-0001-Handle-pg_get_ruledef-default-args-in-system_func.patch)
download | inline diff:
From 9c24ecf0bb50d9e7ca18da532b9765fd521659c2 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Mon, 8 Dec 2025 15:41:07 -0800
Subject: [PATCH v6 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 35083fcc733..6a4c7e4822d 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -569,24 +569,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 99fa9a6ede2..c007d92b7b0 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,9 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ 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',
@@ -8593,7 +8590,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.47.3
[text/x-patch] v6-0002-Handle-pg_get_viewdef-default-args-in-system_func.patch (3.9K, ../../9e3ad0f4-c4ef-436b-a5a1-28f600d76a61@proxel.se/3-v6-0002-Handle-pg_get_viewdef-default-args-in-system_func.patch)
download | inline diff:
From 7a2c0450bd31392a0124e425edd6cb347b63ec0e Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 09:33:21 -0800
Subject: [PATCH v6 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 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,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);
@@ -727,31 +708,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 c007d92b7b0..d9e52018bce 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ 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' },
@@ -8596,12 +8589,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.47.3
[text/x-patch] v6-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch (2.6K, ../../9e3ad0f4-c4ef-436b-a5a1-28f600d76a61@proxel.se/4-v6-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch)
download | inline diff:
From 74aff0343c08fca248b76665804540c07c37c7c3 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 10:02:15 -0800
Subject: [PATCH v6 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 1202cb07c07..55926ec15e0 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -1125,26 +1125,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 d9e52018bce..18b62310922 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3984,9 +3984,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',
@@ -8605,7 +8602,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.47.3
[text/x-patch] v6-0004-Handle-pg_get_constraintdef-default-args-in-syste.patch (2.6K, ../../9e3ad0f4-c4ef-436b-a5a1-28f600d76a61@proxel.se/5-v6-0004-Handle-pg_get_constraintdef-default-args-in-syste.patch)
download | inline diff:
From 85e4ac83e5091fcace385ae389aaa2680b7ba4d6 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 10:59:41 -0800
Subject: [PATCH v6 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 55926ec15e0..2d39bce7fd7 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -2420,23 +2420,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 18b62310922..657a2a7d4f8 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -4006,9 +4006,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' },
@@ -8606,7 +8603,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 => '8760', descr => 'get DDL to recreate a role',
proname => 'pg_get_role_ddl', provariadic => 'text', proisstrict => 'f',
provolatile => 's', proretset => 't', prorows => '10', prorettype => 'text',
--
2.47.3
[text/x-patch] v6-0005-Handle-pg_get_expr-default-args-in-system_functio.patch (3.3K, ../../9e3ad0f4-c4ef-436b-a5a1-28f600d76a61@proxel.se/6-v6-0005-Handle-pg_get_expr-default-args-in-system_functio.patch)
download | inline diff:
From 9c29e0ce8722c5df15eb5f09c3cd36d1966ce395 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 11:17:56 -0800
Subject: [PATCH v6 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 eec09ba1ded..73eb6322daf 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -17695,8 +17695,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 2d39bce7fd7..707f83d4310 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -2932,23 +2932,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 657a2a7d4f8..56d82af5c91 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -4006,9 +4006,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' },
@@ -8640,7 +8637,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.47.3
[text/x-patch] v6-0006-Handle-pg_get_triggerdef-default-args-in-system_f.patch (2.3K, ../../9e3ad0f4-c4ef-436b-a5a1-28f600d76a61@proxel.se/7-v6-0006-Handle-pg_get_triggerdef-default-args-in-system_f.patch)
download | inline diff:
From af5851d73197a582aa1199961f17dc5a8ba7581a Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 11:51:39 -0800
Subject: [PATCH v6 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 707f83d4310..249f4518f62 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -818,20 +818,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 56d82af5c91..1d304d1e316 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -4003,9 +4003,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' },
@@ -8675,7 +8672,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.47.3
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: updates for handling optional argument in system functions
2025-12-09 23:28 updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-02 18:36 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-07 22:26 ` Re: updates for handling optional argument in system functions Andreas Karlsson <andreas@proxel.se>
2026-04-07 23:28 ` Re: updates for handling optional argument in system functions Andreas Karlsson <andreas@proxel.se>
@ 2026-04-07 23:44 ` Mark Wong <markwkm@gmail.com>
2026-04-08 01:33 ` Re: updates for handling optional argument in system functions Chao Li <li.evan.chao@gmail.com>
0 siblings, 1 reply; 31+ messages in thread
From: Mark Wong @ 2026-04-07 23:44 UTC (permalink / raw)
To: Andreas Karlsson <andreas@proxel.se>; +Cc: pgsql-hackers@lists.postgresql.org
On Wed, Apr 08, 2026 at 01:28:29AM +0200, Andreas Karlsson wrote:
> On 4/8/26 12:26 AM, Andreas Karlsson wrote:
> > On 4/2/26 8:36 PM, Mark Wong wrote:
> >> I've attached v5, simply a needed rebase due to some other churn in
> >> pg_proc.dat.
> >
> > Nice, I like the patch. The code changes looks good and I like the
> > removal of these duplicate functions and use of default arguments. But I
> > think the names of the arguments should be aligned with the names we
> > have in the documentation. And that may mean that we should change the
> > documentation.
> Forgot to attach rebased patches.
Another rebase needed so quickly? :) Thanks for the assist!
Regards,
Mark
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: updates for handling optional argument in system functions
2025-12-09 23:28 updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-02 18:36 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-07 22:26 ` Re: updates for handling optional argument in system functions Andreas Karlsson <andreas@proxel.se>
2026-04-07 23:28 ` Re: updates for handling optional argument in system functions Andreas Karlsson <andreas@proxel.se>
2026-04-07 23:44 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
@ 2026-04-08 01:33 ` Chao Li <li.evan.chao@gmail.com>
2026-04-08 01:46 ` Re: updates for handling optional argument in system functions David G. Johnston <david.g.johnston@gmail.com>
0 siblings, 1 reply; 31+ messages in thread
From: Chao Li @ 2026-04-08 01:33 UTC (permalink / raw)
To: Mark Wong <markwkm@gmail.com>; +Cc: Andreas Karlsson <andreas@proxel.se>; pgsql-hackers@lists.postgresql.org
> On Apr 8, 2026, at 07:44, Mark Wong <markwkm@gmail.com> wrote:
>
> On Wed, Apr 08, 2026 at 01:28:29AM +0200, Andreas Karlsson wrote:
>> On 4/8/26 12:26 AM, Andreas Karlsson wrote:
>>> On 4/2/26 8:36 PM, Mark Wong wrote:
>>>> I've attached v5, simply a needed rebase due to some other churn in
>>>> pg_proc.dat.
>>>
>>> Nice, I like the patch. The code changes looks good and I like the
>>> removal of these duplicate functions and use of default arguments. But I
>>> think the names of the arguments should be aligned with the names we
>>> have in the documentation. And that may mean that we should change the
>>> documentation.
>> Forgot to attach rebased patches.
>
> Another rebase needed so quickly? :) Thanks for the assist!
>
> Regards,
> Mark
I still have the question as I raised previously. Let’s use 0001 as an example. 0001 removes function 1573.
Say, an existing view depends on 1573:
```
evantest=# CREATE VIEW v_ruledef AS
evantest-# SELECT pg_get_ruledef(oid) AS ruledef
evantest-# FROM pg_rewrite
evantest-# WHERE rulename = '_RETURN';
CREATE VIEW
```
The view is stored as:
```
_RETURN | v_ruledef | ({QUERY :commandType 1 :querySource 0 :canSetTag true :utilityStmt <> :resultRelation 0 :forPortionOf <> :hasAggs false :hasWindowFuncs false :hasTargetSRFs false :hasSubLinks false :hasDistinctOn false :hasRecursive false :hasModifyingCTE false :hasForUpdate false :hasRowSecurity false :hasGroupRTE false :isReturn false :cteList <> :rtable ({RANGETBLENTRY :alias <> :eref {ALIAS :aliasname pg_rewrite :colnames ("oid" "rulename" "ev_class" "ev_type" "ev_enabled" "is_instead" "ev_qual" "ev_action")} :rtekind 0 :relid 2618 :inh true :relkind r :rellockmode 1 :perminfoindex 1 :tablesample <> :lateral false :inFromCl true :securityQuals <>}) :rteperminfos ({RTEPERMISSIONINFO :relid 2618 :inh true :requiredPerms 2 :checkAsUser 0 :selectedCols (b 8 9) :insertedCols (b) :updatedCols (b)}) :jointree {FROMEXPR :fromlist ({RANGETBLREF :rtindex 1}) :quals {OPEXPR :opno 93 :opfuncid 62 :opresulttype 16 :opretset false :opcollid 0 :inputcollid 950 :args ({VAR :varno 1 :varattno 2 :vartype 19 :vartypmod -1 :varcollid 950 :varnullingrels (b) :varlevelsup 0 :varreturningtype 0 :varnosyn 1 :varattnosyn 2 :location -1} {CONST :consttype 19 :consttypmod -1 :constcollid 950 :constlen 64 :constbyval false :constisnull false :location -1 :constvalue 64 [ 95 82 69 84 85 82 78 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ]}) :location -1}} :mergeActionList <> :mergeTargetRelation 0 :mergeJoinCondition <> :targetList ({TARGETENTRY :expr {FUNCEXPR :funcid 1573 :funcresulttype 25 :funcretset false :funcvariadic false :funcformat 0 :funccollid 100 :inputcollid 0 :args ({VAR :varno 1 :varattno 1 :vartype 26 :vartypmod -1 :varcollid 0 :varnullingrels (b) :varlevelsup 0 :varreturningtype 0 :varnosyn 1 :varattnosyn 1 :location -1}) :location -1} :resno 1 :resname ruledef :ressortgroupref 0 :resorigtbl 0 :resorigcol 0 :resjunk false}) :override 0 :onConflict <> :returningOldAlias <> :returningNewAlias <> :returningList <> :groupClause <> :groupDistinct false :groupByAll false :groupingSets <> :havingQual <> :windowClause <> :distinctClause <> :sortClause <> :limitOffset <> :limitCount <> :limitOption 0 :rowMarks <> :setOperations <> :constraintDeps <> :withCheckOptions <> :stmt_location -1 :stmt_len -1})
```
We can clearly see ":expr {FUNCEXPR :funcid 1573 “.
With this patch, will that view break? How would users find all such broken views? Maybe PostgreSQL already has some recommended way to handle this kind of situation that I am not aware of?
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: updates for handling optional argument in system functions
2025-12-09 23:28 updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-02 18:36 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-07 22:26 ` Re: updates for handling optional argument in system functions Andreas Karlsson <andreas@proxel.se>
2026-04-07 23:28 ` Re: updates for handling optional argument in system functions Andreas Karlsson <andreas@proxel.se>
2026-04-07 23:44 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-08 01:33 ` Re: updates for handling optional argument in system functions Chao Li <li.evan.chao@gmail.com>
@ 2026-04-08 01:46 ` David G. Johnston <david.g.johnston@gmail.com>
2026-04-08 02:09 ` Re: updates for handling optional argument in system functions Chao Li <li.evan.chao@gmail.com>
0 siblings, 1 reply; 31+ messages in thread
From: David G. Johnston @ 2026-04-08 01:46 UTC (permalink / raw)
To: Chao Li <li.evan.chao@gmail.com>; +Cc: Mark Wong <markwkm@gmail.com>; Andreas Karlsson <andreas@proxel.se>; pgsql-hackers@lists.postgresql.org <pgsql-hackers@lists.postgresql.org>
On Tuesday, April 7, 2026, Chao Li <li.evan.chao@gmail.com> wrote:
>
> We can clearly see ":expr {FUNCEXPR :funcid 1573 “.
>
> With this patch, will that view break? How would users find all such
> broken views? Maybe PostgreSQL already has some recommended way to handle
> this kind of situation that I am not aware of?
>
pg_dump resolves oid=1573 and produces a textual SQL representation, which
is then executed during pg_restore. This happens manually, and also
automatically by pg_upgrade. Since the text form hasn’t changed the view
is still valid in v19. You would see the new oid if inspecting the rule
after the upgrade.
So yes, the public serialization format being SQL and thus mandatory new
object creation during upgrade is the way PostgreSQL handles implementation
detail isolation.
David J.
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: updates for handling optional argument in system functions
2025-12-09 23:28 updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-02 18:36 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-07 22:26 ` Re: updates for handling optional argument in system functions Andreas Karlsson <andreas@proxel.se>
2026-04-07 23:28 ` Re: updates for handling optional argument in system functions Andreas Karlsson <andreas@proxel.se>
2026-04-07 23:44 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-08 01:33 ` Re: updates for handling optional argument in system functions Chao Li <li.evan.chao@gmail.com>
2026-04-08 01:46 ` Re: updates for handling optional argument in system functions David G. Johnston <david.g.johnston@gmail.com>
@ 2026-04-08 02:09 ` Chao Li <li.evan.chao@gmail.com>
0 siblings, 0 replies; 31+ messages in thread
From: Chao Li @ 2026-04-08 02:09 UTC (permalink / raw)
To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: Mark Wong <markwkm@gmail.com>; Andreas Karlsson <andreas@proxel.se>; pgsql-hackers@lists.postgresql.org <pgsql-hackers@lists.postgresql.org>
> On Apr 8, 2026, at 09:46, David G. Johnston <david.g.johnston@gmail.com> wrote:
>
> On Tuesday, April 7, 2026, Chao Li <li.evan.chao@gmail.com> wrote:
>
> We can clearly see ":expr {FUNCEXPR :funcid 1573 “.
>
> With this patch, will that view break? How would users find all such broken views? Maybe PostgreSQL already has some recommended way to handle this kind of situation that I am not aware of?
>
> pg_dump resolves oid=1573 and produces a textual SQL representation, which is then executed during pg_restore. This happens manually, and also automatically by pg_upgrade. Since the text form hasn’t changed the view is still valid in v19. You would see the new oid if inspecting the rule after the upgrade.
>
> So yes, the public serialization format being SQL and thus mandatory new object creation during upgrade is the way PostgreSQL handles implementation detail isolation.
>
> David J.
>
Hi David, thanks for the explanation, I really didn’t know that.
Then, the patch looks good to me. GET_PRETTY_FLAGS(false) returns PRETTYFLAG_INDENT, so no behavior change either.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: updates for handling optional argument in system functions
2025-12-09 23:28 updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-02 18:36 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-07 22:26 ` Re: updates for handling optional argument in system functions Andreas Karlsson <andreas@proxel.se>
@ 2026-04-07 23:42 ` Mark Wong <markwkm@gmail.com>
2026-04-07 23:51 ` Re: updates for handling optional argument in system functions Andreas Karlsson <andreas@proxel.se>
1 sibling, 1 reply; 31+ messages in thread
From: Mark Wong @ 2026-04-07 23:42 UTC (permalink / raw)
To: Andreas Karlsson <andreas@proxel.se>; +Cc: pgsql-hackers@lists.postgresql.org
On Wed, Apr 08, 2026 at 12:26:05AM +0200, Andreas Karlsson wrote:
> On 4/2/26 8:36 PM, Mark Wong wrote:
> > I've attached v5, simply a needed rebase due to some other churn in
> > pg_proc.dat.
>
> Nice, I like the patch. The code changes looks good and I like the
> removal of these duplicate functions and use of default arguments. But I
> think the names of the arguments should be aligned with the names we
> have in the documentation. And that may mean that we should change the
> documentation.
Thanks!
> For example:
>
> = Code
>
> pg_get_ruledef(rule, pretty)
>
> = Docs
>
> pg_get_ruledef(rule_oid, pretty_bool)
>
> = Should docs maybe be updated to the following?
>
> pg_get_ruledef(rule oid, pretty bool)
I agree with the aligning the names, but maybe I was looking in a
different place?
In the doc/src/sgml/func/func-info.sgml (a4f774cf1c7e) I think I see
pg_get_ruledef(rule oid, pretty bool) already:
<function>pg_get_ruledef</function> ( <parameter>rule</parameter> <type>oid</type> <optional>, <parameter>pretty</parameter> <type>boolean</type> </optional> )
I don't see any matches when I grep for rule_oid or pretty_bool...
Regards,
Mark
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: updates for handling optional argument in system functions
2025-12-09 23:28 updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-02 18:36 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-07 22:26 ` Re: updates for handling optional argument in system functions Andreas Karlsson <andreas@proxel.se>
2026-04-07 23:42 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
@ 2026-04-07 23:51 ` Andreas Karlsson <andreas@proxel.se>
2026-04-08 18:10 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
0 siblings, 1 reply; 31+ messages in thread
From: Andreas Karlsson @ 2026-04-07 23:51 UTC (permalink / raw)
To: Mark Wong <markwkm@gmail.com>; +Cc: pgsql-hackers@lists.postgresql.org
On 4/8/26 1:42 AM, Mark Wong wrote:
> I don't see any matches when I grep for rule_oid or pretty_bool...
Sorry for the noise, I was looking at an old version of the docs. The
parameters do indeed match the docs. But now that I looked at the
patches again I found a real issue which I think should be fixed.
I think the following:
"select statement of a view with pretty-print option"
should likely just be:
"select statement of a view"
Andreas
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: updates for handling optional argument in system functions
2025-12-09 23:28 updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-02 18:36 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-07 22:26 ` Re: updates for handling optional argument in system functions Andreas Karlsson <andreas@proxel.se>
2026-04-07 23:42 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-07 23:51 ` Re: updates for handling optional argument in system functions Andreas Karlsson <andreas@proxel.se>
@ 2026-04-08 18:10 ` Mark Wong <markwkm@gmail.com>
2026-04-08 19:18 ` Re: updates for handling optional argument in system functions Andreas Karlsson <andreas@proxel.se>
2026-06-05 20:14 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
0 siblings, 2 replies; 31+ messages in thread
From: Mark Wong @ 2026-04-08 18:10 UTC (permalink / raw)
To: Andreas Karlsson <andreas@proxel.se>; +Cc: pgsql-hackers@lists.postgresql.org
On Wed, Apr 08, 2026 at 01:51:30AM +0200, Andreas Karlsson wrote:
> On 4/8/26 1:42 AM, Mark Wong wrote:
> > I don't see any matches when I grep for rule_oid or pretty_bool...
>
> Sorry for the noise, I was looking at an old version of the docs. The
> parameters do indeed match the docs. But now that I looked at the
> patches again I found a real issue which I think should be fixed.
No worries.
> I think the following:
>
> "select statement of a view with pretty-print option"
>
> should likely just be:
>
> "select statement of a view"
Yeah, I agree with that considering that other functions like the recent
get_*_ddl functions have options like that aren't detailed in
pg_proc.dat.
What I pondered over a little bit was whether to flip-flop and remove
the original _ext definitions instead and modify their respective
counterparts that I originally removed. I opted to continue editing what
I started because of the comment that reads "System-view support
functions with pretty-print option", but I don't have any strong
opinions either way.
I've attached v7 with the more succinct descriptions.
Regards,
Mark
From 85d88748afb1de1751d2e044c8455b9477398182 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Mon, 8 Dec 2025 15:41:07 -0800
Subject: [PATCH v7 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 | 8 +++-----
2 files changed, 3 insertions(+), 23 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 35083fcc733..6a4c7e4822d 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -569,24 +569,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 fa9ae79082b..954f611de5b 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,9 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ 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',
@@ -8591,9 +8588,10 @@
prosrc => 'macaddr8_send' },
# System-view support functions with pretty-print option
-{ oid => '2504', descr => 'source text of a rule with pretty-print option',
+{ oid => '2504', descr => 'source text of a rule',
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.52.0
From 2786a1f3ba25f7d41b056f727dede146b708b66d Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 09:33:21 -0800
Subject: [PATCH v7 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 | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,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);
@@ -727,31 +708,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 954f611de5b..8d81dcdc2f6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ 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' },
@@ -8593,15 +8586,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
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',
+ descr => 'select statement of a view',
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.52.0
From d3380c507108a1a782e602564140ca93d927da46 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 10:02:15 -0800
Subject: [PATCH v7 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 | 8 +++-----
2 files changed, 3 insertions(+), 25 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 1202cb07c07..55926ec15e0 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -1125,26 +1125,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 8d81dcdc2f6..dfedf5c2851 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3984,9 +3984,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',
@@ -8603,9 +8600,10 @@
prorettype => 'text', proargtypes => 'oid int4',
prosrc => 'pg_get_viewdef_wrap' },
{ oid => '2507',
- descr => 'index description (full create statement or single expression) with pretty-print option',
+ descr => 'index description',
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.52.0
From 0837ef97325e4ebc46075f57b9166c1b9d2556f7 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 10:59:41 -0800
Subject: [PATCH v7 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 | 8 +++-----
2 files changed, 3 insertions(+), 22 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 55926ec15e0..2d39bce7fd7 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -2420,23 +2420,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 dfedf5c2851..39139fd9e3b 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -4006,9 +4006,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' },
@@ -8604,9 +8601,10 @@
proname => 'pg_get_indexdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid int4 bool', proargnames => '{index,column,pretty}',
proargdefaults => '{0,false}', prosrc => 'pg_get_indexdef' },
-{ oid => '2508', descr => 'constraint description with pretty-print option',
+{ oid => '2508', descr => 'constraint description',
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 => '8760', descr => 'get DDL to recreate a role',
proname => 'pg_get_role_ddl', provariadic => 'text', proisstrict => 'f',
provolatile => 's', proretset => 't', prorows => '10', prorettype => 'text',
--
2.52.0
From beac071c5bf090426f9f69d9a6a2844e901d39a8 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 11:17:56 -0800
Subject: [PATCH v7 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 | 9 ++++-----
3 files changed, 7 insertions(+), 24 deletions(-)
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index eec09ba1ded..73eb6322daf 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -17695,8 +17695,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 2d39bce7fd7..707f83d4310 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -2932,23 +2932,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 39139fd9e3b..855529509de 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -4006,9 +4006,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' },
@@ -8638,9 +8635,11 @@
pronargdefaults => '1', proargdefaults => '{NULL}',
prosrc => 'pg_get_database_ddl' },
{ oid => '2509',
- descr => 'deparse an encoded expression with pretty-print option',
+ descr => 'deparse an encoded expression',
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.52.0
From 127f562b0cbfe56229346fed6e281d77471956db Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 11:51:39 -0800
Subject: [PATCH v7 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 | 8 +++-----
2 files changed, 3 insertions(+), 19 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 707f83d4310..249f4518f62 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -818,20 +818,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 855529509de..f4df55370e7 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -4003,9 +4003,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' },
@@ -8673,9 +8670,10 @@
proallargtypes => '{text,text,interval,bool}', proargmodes => '{o,o,o,o}',
proargnames => '{name,abbrev,utc_offset,is_dst}',
prosrc => 'pg_timezone_names' },
-{ oid => '2730', descr => 'trigger description with pretty-print option',
+{ oid => '2730', descr => 'trigger description',
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.52.0
Attachments:
[text/plain] v7-0001-Handle-pg_get_ruledef-default-args-in-system_func.patch (2.6K, ../../adaaL5VD9bfipZQI@ltdrgnflg2/2-v7-0001-Handle-pg_get_ruledef-default-args-in-system_func.patch)
download | inline diff:
From 85d88748afb1de1751d2e044c8455b9477398182 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Mon, 8 Dec 2025 15:41:07 -0800
Subject: [PATCH v7 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 | 8 +++-----
2 files changed, 3 insertions(+), 23 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 35083fcc733..6a4c7e4822d 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -569,24 +569,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 fa9ae79082b..954f611de5b 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,9 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ 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',
@@ -8591,9 +8588,10 @@
prosrc => 'macaddr8_send' },
# System-view support functions with pretty-print option
-{ oid => '2504', descr => 'source text of a rule with pretty-print option',
+{ oid => '2504', descr => 'source text of a rule',
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.52.0
[text/plain] v7-0002-Handle-pg_get_viewdef-default-args-in-system_func.patch (4.1K, ../../adaaL5VD9bfipZQI@ltdrgnflg2/3-v7-0002-Handle-pg_get_viewdef-default-args-in-system_func.patch)
download | inline diff:
From 2786a1f3ba25f7d41b056f727dede146b708b66d Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 09:33:21 -0800
Subject: [PATCH v7 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 | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,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);
@@ -727,31 +708,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 954f611de5b..8d81dcdc2f6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ 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' },
@@ -8593,15 +8586,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
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',
+ descr => 'select statement of a view',
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.52.0
[text/plain] v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch (2.8K, ../../adaaL5VD9bfipZQI@ltdrgnflg2/4-v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch)
download | inline diff:
From d3380c507108a1a782e602564140ca93d927da46 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 10:02:15 -0800
Subject: [PATCH v7 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 | 8 +++-----
2 files changed, 3 insertions(+), 25 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 1202cb07c07..55926ec15e0 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -1125,26 +1125,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 8d81dcdc2f6..dfedf5c2851 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3984,9 +3984,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',
@@ -8603,9 +8600,10 @@
prorettype => 'text', proargtypes => 'oid int4',
prosrc => 'pg_get_viewdef_wrap' },
{ oid => '2507',
- descr => 'index description (full create statement or single expression) with pretty-print option',
+ descr => 'index description',
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.52.0
[text/plain] v7-0004-Handle-pg_get_constraintdef-default-args-in-syste.patch (2.8K, ../../adaaL5VD9bfipZQI@ltdrgnflg2/5-v7-0004-Handle-pg_get_constraintdef-default-args-in-syste.patch)
download | inline diff:
From 0837ef97325e4ebc46075f57b9166c1b9d2556f7 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 10:59:41 -0800
Subject: [PATCH v7 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 | 8 +++-----
2 files changed, 3 insertions(+), 22 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 55926ec15e0..2d39bce7fd7 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -2420,23 +2420,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 dfedf5c2851..39139fd9e3b 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -4006,9 +4006,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' },
@@ -8604,9 +8601,10 @@
proname => 'pg_get_indexdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid int4 bool', proargnames => '{index,column,pretty}',
proargdefaults => '{0,false}', prosrc => 'pg_get_indexdef' },
-{ oid => '2508', descr => 'constraint description with pretty-print option',
+{ oid => '2508', descr => 'constraint description',
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 => '8760', descr => 'get DDL to recreate a role',
proname => 'pg_get_role_ddl', provariadic => 'text', proisstrict => 'f',
provolatile => 's', proretset => 't', prorows => '10', prorettype => 'text',
--
2.52.0
[text/plain] v7-0005-Handle-pg_get_expr-default-args-in-system_functio.patch (3.5K, ../../adaaL5VD9bfipZQI@ltdrgnflg2/6-v7-0005-Handle-pg_get_expr-default-args-in-system_functio.patch)
download | inline diff:
From beac071c5bf090426f9f69d9a6a2844e901d39a8 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 11:17:56 -0800
Subject: [PATCH v7 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 | 9 ++++-----
3 files changed, 7 insertions(+), 24 deletions(-)
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index eec09ba1ded..73eb6322daf 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -17695,8 +17695,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 2d39bce7fd7..707f83d4310 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -2932,23 +2932,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 39139fd9e3b..855529509de 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -4006,9 +4006,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' },
@@ -8638,9 +8635,11 @@
pronargdefaults => '1', proargdefaults => '{NULL}',
prosrc => 'pg_get_database_ddl' },
{ oid => '2509',
- descr => 'deparse an encoded expression with pretty-print option',
+ descr => 'deparse an encoded expression',
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.52.0
[text/plain] v7-0006-Handle-pg_get_triggerdef-default-args-in-system_f.patch (2.5K, ../../adaaL5VD9bfipZQI@ltdrgnflg2/7-v7-0006-Handle-pg_get_triggerdef-default-args-in-system_f.patch)
download | inline diff:
From 127f562b0cbfe56229346fed6e281d77471956db Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 11:51:39 -0800
Subject: [PATCH v7 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 | 8 +++-----
2 files changed, 3 insertions(+), 19 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 707f83d4310..249f4518f62 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -818,20 +818,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 855529509de..f4df55370e7 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -4003,9 +4003,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' },
@@ -8673,9 +8670,10 @@
proallargtypes => '{text,text,interval,bool}', proargmodes => '{o,o,o,o}',
proargnames => '{name,abbrev,utc_offset,is_dst}',
prosrc => 'pg_timezone_names' },
-{ oid => '2730', descr => 'trigger description with pretty-print option',
+{ oid => '2730', descr => 'trigger description',
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.52.0
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: updates for handling optional argument in system functions
2025-12-09 23:28 updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-02 18:36 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-07 22:26 ` Re: updates for handling optional argument in system functions Andreas Karlsson <andreas@proxel.se>
2026-04-07 23:42 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-07 23:51 ` Re: updates for handling optional argument in system functions Andreas Karlsson <andreas@proxel.se>
2026-04-08 18:10 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
@ 2026-04-08 19:18 ` Andreas Karlsson <andreas@proxel.se>
1 sibling, 0 replies; 31+ messages in thread
From: Andreas Karlsson @ 2026-04-08 19:18 UTC (permalink / raw)
To: Mark Wong <markwkm@gmail.com>; +Cc: pgsql-hackers@lists.postgresql.org
On 4/8/26 8:10 PM, Mark Wong wrote:
> What I pondered over a little bit was whether to flip-flop and remove
> the original _ext definitions instead and modify their respective
> counterparts that I originally removed. I opted to continue editing what
> I started because of the comment that reads "System-view support
> functions with pretty-print option", but I don't have any strong
> opinions either way.
>
> I've attached v7 with the more succinct descriptions.
I would be fine with either too. The comment feels a bit less useful now
so it too could either stay or go. I have no strong feelings about it.
Setting this as ready for committer since I think the patch is fine
as-is and an improvement over the current no matter what is done about
the comment or which oids we decide to use.
Andreas
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: updates for handling optional argument in system functions
2025-12-09 23:28 updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-02 18:36 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-07 22:26 ` Re: updates for handling optional argument in system functions Andreas Karlsson <andreas@proxel.se>
2026-04-07 23:42 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-07 23:51 ` Re: updates for handling optional argument in system functions Andreas Karlsson <andreas@proxel.se>
2026-04-08 18:10 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
@ 2026-06-05 20:14 ` Mark Wong <markwkm@gmail.com>
2026-06-05 21:04 ` Re: updates for handling optional argument in system functions Tristan Partin <tristan@partin.io>
1 sibling, 1 reply; 31+ messages in thread
From: Mark Wong @ 2026-06-05 20:14 UTC (permalink / raw)
To: pgsql-hackers@lists.postgresql.org
I noticed a rebase was needed so I've attached v8.
Regards,
Mark
From e3683d186b819489697e929fe2e0c5768fc38dee Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Mon, 8 Dec 2025 15:41:07 -0800
Subject: [PATCH v8 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 | 8 +++-----
2 files changed, 3 insertions(+), 23 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 88de5c0481c..76705db3dac 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -569,24 +569,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 be157a5fbe9..45e4483692d 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,9 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ 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',
@@ -8565,9 +8562,10 @@
prosrc => 'macaddr8_send' },
# System-view support functions with pretty-print option
-{ oid => '2504', descr => 'source text of a rule with pretty-print option',
+{ oid => '2504', descr => 'source text of a rule',
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.53.0
From ec9960dff8dcaf63d3bb0baa9ce46b30299c3d23 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 09:33:21 -0800
Subject: [PATCH v8 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 | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,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);
@@ -727,31 +708,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 45e4483692d..5b22fdc8e08 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ 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' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
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',
+ descr => 'select statement of a view',
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.53.0
From 2bf8e5be79165f1aaf1b1d0da0dea2bd8802fadf Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 10:02:15 -0800
Subject: [PATCH v8 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 | 8 +++-----
2 files changed, 3 insertions(+), 25 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index fd00d6c3515..f2edf61f9a0 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -1125,26 +1125,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 5b22fdc8e08..6bf78edf535 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3984,9 +3984,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',
@@ -8577,9 +8574,10 @@
prorettype => 'text', proargtypes => 'oid int4',
prosrc => 'pg_get_viewdef_wrap' },
{ oid => '2507',
- descr => 'index description (full create statement or single expression) with pretty-print option',
+ descr => 'index description',
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.53.0
From 7a2d20a1191cdc474f6b02659c91308521a0d83a Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 10:59:41 -0800
Subject: [PATCH v8 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 | 8 +++-----
2 files changed, 3 insertions(+), 22 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index f2edf61f9a0..d83be8cf77d 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -2420,23 +2420,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 6bf78edf535..7e452aa8c27 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -4006,9 +4006,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' },
@@ -8578,9 +8575,10 @@
proname => 'pg_get_indexdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid int4 bool', proargnames => '{index,column,pretty}',
proargdefaults => '{0,false}', prosrc => 'pg_get_indexdef' },
-{ oid => '2508', descr => 'constraint description with pretty-print option',
+{ oid => '2508', descr => 'constraint description',
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 => '6501', descr => 'get DDL to recreate a role',
proname => 'pg_get_role_ddl', prorows => '10', provariadic => 'text',
proisstrict => 'f', proretset => 't', provolatile => 's',
--
2.53.0
From 39c96853e455cf7972a26fd1caf213ab278a1517 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 11:17:56 -0800
Subject: [PATCH v8 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 | 9 ++++-----
3 files changed, 7 insertions(+), 24 deletions(-)
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index a1845240a98..f063f744f6d 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -17730,8 +17730,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 d83be8cf77d..e60478677e0 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -2932,23 +2932,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 7e452aa8c27..71bd2aaf3d9 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -4006,9 +4006,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' },
@@ -8605,9 +8602,11 @@
proargmodes => '{i,v}', proargdefaults => '{NULL}',
prosrc => 'pg_get_database_ddl' },
{ oid => '2509',
- descr => 'deparse an encoded expression with pretty-print option',
+ descr => 'deparse an encoded expression',
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.53.0
From b9bcffbbb9b269fd12a92fdbf50e14ad93d33be2 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 11:51:39 -0800
Subject: [PATCH v8 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 | 8 +++-----
2 files changed, 3 insertions(+), 19 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index e60478677e0..bfa5ef7910b 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -818,20 +818,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 71bd2aaf3d9..d7a6493dd19 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -4003,9 +4003,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' },
@@ -8640,9 +8637,10 @@
proallargtypes => '{text,text,interval,bool}', proargmodes => '{o,o,o,o}',
proargnames => '{name,abbrev,utc_offset,is_dst}',
prosrc => 'pg_timezone_names' },
-{ oid => '2730', descr => 'trigger description with pretty-print option',
+{ oid => '2730', descr => 'trigger description',
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.53.0
Attachments:
[text/plain] v8-0001-Handle-pg_get_ruledef-default-args-in-system_func.patch (2.6K, ../../aiMuFBFYLAWQC_5Z@ltdrgnflg2/2-v8-0001-Handle-pg_get_ruledef-default-args-in-system_func.patch)
download | inline diff:
From e3683d186b819489697e929fe2e0c5768fc38dee Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Mon, 8 Dec 2025 15:41:07 -0800
Subject: [PATCH v8 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 | 8 +++-----
2 files changed, 3 insertions(+), 23 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 88de5c0481c..76705db3dac 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -569,24 +569,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 be157a5fbe9..45e4483692d 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,9 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ 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',
@@ -8565,9 +8562,10 @@
prosrc => 'macaddr8_send' },
# System-view support functions with pretty-print option
-{ oid => '2504', descr => 'source text of a rule with pretty-print option',
+{ oid => '2504', descr => 'source text of a rule',
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.53.0
[text/plain] v8-0002-Handle-pg_get_viewdef-default-args-in-system_func.patch (4.1K, ../../aiMuFBFYLAWQC_5Z@ltdrgnflg2/3-v8-0002-Handle-pg_get_viewdef-default-args-in-system_func.patch)
download | inline diff:
From ec9960dff8dcaf63d3bb0baa9ce46b30299c3d23 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 09:33:21 -0800
Subject: [PATCH v8 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 | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,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);
@@ -727,31 +708,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 45e4483692d..5b22fdc8e08 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ 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' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
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',
+ descr => 'select statement of a view',
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.53.0
[text/plain] v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch (2.8K, ../../aiMuFBFYLAWQC_5Z@ltdrgnflg2/4-v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch)
download | inline diff:
From 2bf8e5be79165f1aaf1b1d0da0dea2bd8802fadf Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 10:02:15 -0800
Subject: [PATCH v8 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 | 8 +++-----
2 files changed, 3 insertions(+), 25 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index fd00d6c3515..f2edf61f9a0 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -1125,26 +1125,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 5b22fdc8e08..6bf78edf535 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3984,9 +3984,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',
@@ -8577,9 +8574,10 @@
prorettype => 'text', proargtypes => 'oid int4',
prosrc => 'pg_get_viewdef_wrap' },
{ oid => '2507',
- descr => 'index description (full create statement or single expression) with pretty-print option',
+ descr => 'index description',
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.53.0
[text/plain] v8-0004-Handle-pg_get_constraintdef-default-args-in-syste.patch (2.8K, ../../aiMuFBFYLAWQC_5Z@ltdrgnflg2/5-v8-0004-Handle-pg_get_constraintdef-default-args-in-syste.patch)
download | inline diff:
From 7a2d20a1191cdc474f6b02659c91308521a0d83a Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 10:59:41 -0800
Subject: [PATCH v8 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 | 8 +++-----
2 files changed, 3 insertions(+), 22 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index f2edf61f9a0..d83be8cf77d 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -2420,23 +2420,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 6bf78edf535..7e452aa8c27 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -4006,9 +4006,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' },
@@ -8578,9 +8575,10 @@
proname => 'pg_get_indexdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid int4 bool', proargnames => '{index,column,pretty}',
proargdefaults => '{0,false}', prosrc => 'pg_get_indexdef' },
-{ oid => '2508', descr => 'constraint description with pretty-print option',
+{ oid => '2508', descr => 'constraint description',
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 => '6501', descr => 'get DDL to recreate a role',
proname => 'pg_get_role_ddl', prorows => '10', provariadic => 'text',
proisstrict => 'f', proretset => 't', provolatile => 's',
--
2.53.0
[text/plain] v8-0005-Handle-pg_get_expr-default-args-in-system_functio.patch (3.5K, ../../aiMuFBFYLAWQC_5Z@ltdrgnflg2/6-v8-0005-Handle-pg_get_expr-default-args-in-system_functio.patch)
download | inline diff:
From 39c96853e455cf7972a26fd1caf213ab278a1517 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 11:17:56 -0800
Subject: [PATCH v8 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 | 9 ++++-----
3 files changed, 7 insertions(+), 24 deletions(-)
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index a1845240a98..f063f744f6d 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -17730,8 +17730,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 d83be8cf77d..e60478677e0 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -2932,23 +2932,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 7e452aa8c27..71bd2aaf3d9 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -4006,9 +4006,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' },
@@ -8605,9 +8602,11 @@
proargmodes => '{i,v}', proargdefaults => '{NULL}',
prosrc => 'pg_get_database_ddl' },
{ oid => '2509',
- descr => 'deparse an encoded expression with pretty-print option',
+ descr => 'deparse an encoded expression',
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.53.0
[text/plain] v8-0006-Handle-pg_get_triggerdef-default-args-in-system_f.patch (2.5K, ../../aiMuFBFYLAWQC_5Z@ltdrgnflg2/7-v8-0006-Handle-pg_get_triggerdef-default-args-in-system_f.patch)
download | inline diff:
From b9bcffbbb9b269fd12a92fdbf50e14ad93d33be2 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 11:51:39 -0800
Subject: [PATCH v8 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 | 8 +++-----
2 files changed, 3 insertions(+), 19 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index e60478677e0..bfa5ef7910b 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -818,20 +818,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 71bd2aaf3d9..d7a6493dd19 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -4003,9 +4003,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' },
@@ -8640,9 +8637,10 @@
proallargtypes => '{text,text,interval,bool}', proargmodes => '{o,o,o,o}',
proargnames => '{name,abbrev,utc_offset,is_dst}',
prosrc => 'pg_timezone_names' },
-{ oid => '2730', descr => 'trigger description with pretty-print option',
+{ oid => '2730', descr => 'trigger description',
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.53.0
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: updates for handling optional argument in system functions
2025-12-09 23:28 updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-02 18:36 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-07 22:26 ` Re: updates for handling optional argument in system functions Andreas Karlsson <andreas@proxel.se>
2026-04-07 23:42 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-07 23:51 ` Re: updates for handling optional argument in system functions Andreas Karlsson <andreas@proxel.se>
2026-04-08 18:10 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-06-05 20:14 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
@ 2026-06-05 21:04 ` Tristan Partin <tristan@partin.io>
2026-06-11 14:47 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
0 siblings, 1 reply; 31+ messages in thread
From: Tristan Partin @ 2026-06-05 21:04 UTC (permalink / raw)
To: Mark Wong <markwkm@gmail.com>; +Cc: pgsql-hackers@lists.postgresql.org
> Patch 1
>
> - proargtypes => 'oid bool', prosrc => 'pg_get_ruledef_ext' },
> + proargtypes => 'oid bool', proargnames => '{rule,pretty}',
> + proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
There is a space missing before prosrc in the added line.
Other than that one comment, this looks good to me.
I am a little confused how proargdefaults works given the function takes
two arguments, but you only defined one default, so how does the parser
know that the false default is in reference to "pretty". I do see there
is other precedent for this pattern, so it is correct.
--
Tristan Partin
PostgreSQL Contributors Team
AWS (https://aws.amazon.com)
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: updates for handling optional argument in system functions
2025-12-09 23:28 updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-02 18:36 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-07 22:26 ` Re: updates for handling optional argument in system functions Andreas Karlsson <andreas@proxel.se>
2026-04-07 23:42 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-07 23:51 ` Re: updates for handling optional argument in system functions Andreas Karlsson <andreas@proxel.se>
2026-04-08 18:10 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-06-05 20:14 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-06-05 21:04 ` Re: updates for handling optional argument in system functions Tristan Partin <tristan@partin.io>
@ 2026-06-11 14:47 ` Mark Wong <markwkm@gmail.com>
2026-06-18 16:50 ` Re: updates for handling optional argument in system functions Tristan Partin <tristan@partin.io>
2026-09-12 00:22 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
0 siblings, 2 replies; 31+ messages in thread
From: Mark Wong @ 2026-06-11 14:47 UTC (permalink / raw)
To: Tristan Partin <tristan@partin.io>; +Cc: pgsql-hackers@lists.postgresql.org
On Fri, Jun 05, 2026 at 09:04:34PM +0000, Tristan Partin wrote:
> > Patch 1
> >
> > - proargtypes => 'oid bool', prosrc => 'pg_get_ruledef_ext' },
> > + proargtypes => 'oid bool', proargnames => '{rule,pretty}',
> > + proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
>
> There is a space missing before prosrc in the added line.
>
> Other than that one comment, this looks good to me.
Oops, v8.1 attached to correct that white space.
> I am a little confused how proargdefaults works given the function takes
> two arguments, but you only defined one default, so how does the parser
> know that the false default is in reference to "pretty". I do see there
> is other precedent for this pattern, so it is correct.
I believe that's handled in InsertOneProargdefaultsValue() in
src/backend/bootstrap/bootstrap.c, right below the comment:
/* The values should correspond to the last N argtypes */
Regards,
Mark
From 5c9b16d75d203edb4b19bcd2d4ca1d3fb9a824c8 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Mon, 8 Dec 2025 15:41:07 -0800
Subject: [PATCH v8.1 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 | 8 +++-----
2 files changed, 3 insertions(+), 23 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 88de5c0481c..76705db3dac 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -569,24 +569,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 be157a5fbe9..49e92204bd6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,9 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ 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',
@@ -8565,9 +8562,10 @@
prosrc => 'macaddr8_send' },
# System-view support functions with pretty-print option
-{ oid => '2504', descr => 'source text of a rule with pretty-print option',
+{ oid => '2504', descr => 'source text of a rule',
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.53.0
From 85072dba8fdebb835d1b6b3c25d67a81c03130a1 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 09:33:21 -0800
Subject: [PATCH v8.1 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 | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,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);
@@ -727,31 +708,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 49e92204bd6..b00ede45e41 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ 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' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
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',
+ descr => 'select statement of a view',
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.53.0
From 6c4104d9b7345a4d86152be633b1e6edcdeba1f2 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 10:02:15 -0800
Subject: [PATCH v8.1 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 | 8 +++-----
2 files changed, 3 insertions(+), 25 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index fd00d6c3515..f2edf61f9a0 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -1125,26 +1125,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 b00ede45e41..d39852c8323 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3984,9 +3984,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',
@@ -8577,9 +8574,10 @@
prorettype => 'text', proargtypes => 'oid int4',
prosrc => 'pg_get_viewdef_wrap' },
{ oid => '2507',
- descr => 'index description (full create statement or single expression) with pretty-print option',
+ descr => 'index description',
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.53.0
From 0c969f9454f19c5b250045173540eca736beb6d8 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 10:59:41 -0800
Subject: [PATCH v8.1 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 | 8 +++-----
2 files changed, 3 insertions(+), 22 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index f2edf61f9a0..d83be8cf77d 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -2420,23 +2420,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 d39852c8323..e610a6213ec 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -4006,9 +4006,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' },
@@ -8578,9 +8575,10 @@
proname => 'pg_get_indexdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid int4 bool', proargnames => '{index,column,pretty}',
proargdefaults => '{0,false}', prosrc => 'pg_get_indexdef' },
-{ oid => '2508', descr => 'constraint description with pretty-print option',
+{ oid => '2508', descr => 'constraint description',
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 => '6501', descr => 'get DDL to recreate a role',
proname => 'pg_get_role_ddl', prorows => '10', provariadic => 'text',
proisstrict => 'f', proretset => 't', provolatile => 's',
--
2.53.0
From ffc72c733678d850c227c15ab08069463b1d0934 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 11:17:56 -0800
Subject: [PATCH v8.1 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 | 9 ++++-----
3 files changed, 7 insertions(+), 24 deletions(-)
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index a1845240a98..f063f744f6d 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -17730,8 +17730,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 d83be8cf77d..e60478677e0 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -2932,23 +2932,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 e610a6213ec..df43469be3d 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -4006,9 +4006,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' },
@@ -8605,9 +8602,11 @@
proargmodes => '{i,v}', proargdefaults => '{NULL}',
prosrc => 'pg_get_database_ddl' },
{ oid => '2509',
- descr => 'deparse an encoded expression with pretty-print option',
+ descr => 'deparse an encoded expression',
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.53.0
From dc71290e489d74c1c40e633b49fb08a01c9e575e Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 11:51:39 -0800
Subject: [PATCH v8.1 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 | 8 +++-----
2 files changed, 3 insertions(+), 19 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index e60478677e0..bfa5ef7910b 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -818,20 +818,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 df43469be3d..7cccfe6d7a7 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -4003,9 +4003,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' },
@@ -8640,9 +8637,10 @@
proallargtypes => '{text,text,interval,bool}', proargmodes => '{o,o,o,o}',
proargnames => '{name,abbrev,utc_offset,is_dst}',
prosrc => 'pg_timezone_names' },
-{ oid => '2730', descr => 'trigger description with pretty-print option',
+{ oid => '2730', descr => 'trigger description',
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.53.0
Attachments:
[text/plain] v8.1-0001-Handle-pg_get_ruledef-default-args-in-system_fu.patch (2.6K, ../../airKicKeRJaaoMF5@ltdrgnflg2/2-v8.1-0001-Handle-pg_get_ruledef-default-args-in-system_fu.patch)
download | inline diff:
From 5c9b16d75d203edb4b19bcd2d4ca1d3fb9a824c8 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Mon, 8 Dec 2025 15:41:07 -0800
Subject: [PATCH v8.1 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 | 8 +++-----
2 files changed, 3 insertions(+), 23 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 88de5c0481c..76705db3dac 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -569,24 +569,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 be157a5fbe9..49e92204bd6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,9 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ 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',
@@ -8565,9 +8562,10 @@
prosrc => 'macaddr8_send' },
# System-view support functions with pretty-print option
-{ oid => '2504', descr => 'source text of a rule with pretty-print option',
+{ oid => '2504', descr => 'source text of a rule',
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.53.0
[text/plain] v8.1-0002-Handle-pg_get_viewdef-default-args-in-system_fu.patch (4.1K, ../../airKicKeRJaaoMF5@ltdrgnflg2/3-v8.1-0002-Handle-pg_get_viewdef-default-args-in-system_fu.patch)
download | inline diff:
From 85072dba8fdebb835d1b6b3c25d67a81c03130a1 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 09:33:21 -0800
Subject: [PATCH v8.1 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 | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,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);
@@ -727,31 +708,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 49e92204bd6..b00ede45e41 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ 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' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
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',
+ descr => 'select statement of a view',
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.53.0
[text/plain] v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch (2.8K, ../../airKicKeRJaaoMF5@ltdrgnflg2/4-v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch)
download | inline diff:
From 6c4104d9b7345a4d86152be633b1e6edcdeba1f2 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 10:02:15 -0800
Subject: [PATCH v8.1 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 | 8 +++-----
2 files changed, 3 insertions(+), 25 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index fd00d6c3515..f2edf61f9a0 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -1125,26 +1125,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 b00ede45e41..d39852c8323 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3984,9 +3984,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',
@@ -8577,9 +8574,10 @@
prorettype => 'text', proargtypes => 'oid int4',
prosrc => 'pg_get_viewdef_wrap' },
{ oid => '2507',
- descr => 'index description (full create statement or single expression) with pretty-print option',
+ descr => 'index description',
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.53.0
[text/plain] v8.1-0004-Handle-pg_get_constraintdef-default-args-in-sys.patch (2.8K, ../../airKicKeRJaaoMF5@ltdrgnflg2/5-v8.1-0004-Handle-pg_get_constraintdef-default-args-in-sys.patch)
download | inline diff:
From 0c969f9454f19c5b250045173540eca736beb6d8 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 10:59:41 -0800
Subject: [PATCH v8.1 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 | 8 +++-----
2 files changed, 3 insertions(+), 22 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index f2edf61f9a0..d83be8cf77d 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -2420,23 +2420,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 d39852c8323..e610a6213ec 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -4006,9 +4006,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' },
@@ -8578,9 +8575,10 @@
proname => 'pg_get_indexdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid int4 bool', proargnames => '{index,column,pretty}',
proargdefaults => '{0,false}', prosrc => 'pg_get_indexdef' },
-{ oid => '2508', descr => 'constraint description with pretty-print option',
+{ oid => '2508', descr => 'constraint description',
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 => '6501', descr => 'get DDL to recreate a role',
proname => 'pg_get_role_ddl', prorows => '10', provariadic => 'text',
proisstrict => 'f', proretset => 't', provolatile => 's',
--
2.53.0
[text/plain] v8.1-0005-Handle-pg_get_expr-default-args-in-system_funct.patch (3.5K, ../../airKicKeRJaaoMF5@ltdrgnflg2/6-v8.1-0005-Handle-pg_get_expr-default-args-in-system_funct.patch)
download | inline diff:
From ffc72c733678d850c227c15ab08069463b1d0934 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 11:17:56 -0800
Subject: [PATCH v8.1 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 | 9 ++++-----
3 files changed, 7 insertions(+), 24 deletions(-)
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index a1845240a98..f063f744f6d 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -17730,8 +17730,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 d83be8cf77d..e60478677e0 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -2932,23 +2932,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 e610a6213ec..df43469be3d 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -4006,9 +4006,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' },
@@ -8605,9 +8602,11 @@
proargmodes => '{i,v}', proargdefaults => '{NULL}',
prosrc => 'pg_get_database_ddl' },
{ oid => '2509',
- descr => 'deparse an encoded expression with pretty-print option',
+ descr => 'deparse an encoded expression',
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.53.0
[text/plain] v8.1-0006-Handle-pg_get_triggerdef-default-args-in-system.patch (2.5K, ../../airKicKeRJaaoMF5@ltdrgnflg2/7-v8.1-0006-Handle-pg_get_triggerdef-default-args-in-system.patch)
download | inline diff:
From dc71290e489d74c1c40e633b49fb08a01c9e575e Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 11:51:39 -0800
Subject: [PATCH v8.1 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 | 8 +++-----
2 files changed, 3 insertions(+), 19 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index e60478677e0..bfa5ef7910b 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -818,20 +818,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 df43469be3d..7cccfe6d7a7 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -4003,9 +4003,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' },
@@ -8640,9 +8637,10 @@
proallargtypes => '{text,text,interval,bool}', proargmodes => '{o,o,o,o}',
proargnames => '{name,abbrev,utc_offset,is_dst}',
prosrc => 'pg_timezone_names' },
-{ oid => '2730', descr => 'trigger description with pretty-print option',
+{ oid => '2730', descr => 'trigger description',
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.53.0
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: updates for handling optional argument in system functions
2025-12-09 23:28 updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-02 18:36 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-07 22:26 ` Re: updates for handling optional argument in system functions Andreas Karlsson <andreas@proxel.se>
2026-04-07 23:42 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-07 23:51 ` Re: updates for handling optional argument in system functions Andreas Karlsson <andreas@proxel.se>
2026-04-08 18:10 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-06-05 20:14 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-06-05 21:04 ` Re: updates for handling optional argument in system functions Tristan Partin <tristan@partin.io>
2026-06-11 14:47 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
@ 2026-06-18 16:50 ` Tristan Partin <tristan@partin.io>
2026-07-03 13:59 ` Re: updates for handling optional argument in system functions Fujii Masao <masao.fujii@gmail.com>
1 sibling, 1 reply; 31+ messages in thread
From: Tristan Partin @ 2026-06-18 16:50 UTC (permalink / raw)
To: Mark Wong <markwkm@gmail.com>; +Cc: pgsql-hackers@lists.postgresql.org
On Thu Jun 11, 2026 at 2:47 PM UTC, Mark Wong wrote:
> On Fri, Jun 05, 2026 at 09:04:34PM +0000, Tristan Partin wrote:
>> > Patch 1
>> >
>> > - proargtypes => 'oid bool', prosrc => 'pg_get_ruledef_ext' },
>> > + proargtypes => 'oid bool', proargnames => '{rule,pretty}',
>> > + proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
>>
>> There is a space missing before prosrc in the added line.
>>
>> Other than that one comment, this looks good to me.
>
> Oops, v8.1 attached to correct that white space.
Patches look great Mark!
--
Tristan Partin
PostgreSQL Contributors Team
AWS (https://aws.amazon.com)
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: updates for handling optional argument in system functions
2025-12-09 23:28 updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-02 18:36 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-07 22:26 ` Re: updates for handling optional argument in system functions Andreas Karlsson <andreas@proxel.se>
2026-04-07 23:42 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-07 23:51 ` Re: updates for handling optional argument in system functions Andreas Karlsson <andreas@proxel.se>
2026-04-08 18:10 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-06-05 20:14 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-06-05 21:04 ` Re: updates for handling optional argument in system functions Tristan Partin <tristan@partin.io>
2026-06-11 14:47 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-06-18 16:50 ` Re: updates for handling optional argument in system functions Tristan Partin <tristan@partin.io>
@ 2026-07-03 13:59 ` Fujii Masao <masao.fujii@gmail.com>
2026-07-03 14:15 ` Re: updates for handling optional argument in system functions Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 31+ messages in thread
From: Fujii Masao @ 2026-07-03 13:59 UTC (permalink / raw)
To: Tristan Partin <tristan@partin.io>; +Cc: Mark Wong <markwkm@gmail.com>; pgsql-hackers@lists.postgresql.org
On Fri, Jun 19, 2026 at 1:50 AM Tristan Partin <tristan@partin.io> wrote:
> > Oops, v8.1 attached to correct that white space.
>
> Patches look great Mark!
Some patches no longer apply cleanly on HEAD, so they'll need to be rebased.
I have one question, though.
Suppose a user executes GRANT or REVOKE on pg_get_ruledef(oid), then
creates a dump with pg_dump. If that dump is restored into a newer
server where these patches have been applied, the restore would fail
because pg_get_ruledef(oid) no longer exists.
Is that acceptable (this means that users need to handle the restore
failure), or should pg_dump handle this case specially?
I suspect we've had similar situations before when system functions
changed between major versions, and I don't recall adding special
handling to pg_dump... Thought?
Regards,
--
Fujii Masao
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: updates for handling optional argument in system functions
2025-12-09 23:28 updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-02 18:36 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-07 22:26 ` Re: updates for handling optional argument in system functions Andreas Karlsson <andreas@proxel.se>
2026-04-07 23:42 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-07 23:51 ` Re: updates for handling optional argument in system functions Andreas Karlsson <andreas@proxel.se>
2026-04-08 18:10 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-06-05 20:14 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-06-05 21:04 ` Re: updates for handling optional argument in system functions Tristan Partin <tristan@partin.io>
2026-06-11 14:47 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-06-18 16:50 ` Re: updates for handling optional argument in system functions Tristan Partin <tristan@partin.io>
2026-07-03 13:59 ` Re: updates for handling optional argument in system functions Fujii Masao <masao.fujii@gmail.com>
@ 2026-07-03 14:15 ` Tom Lane <tgl@sss.pgh.pa.us>
2026-07-03 15:01 ` Re: updates for handling optional argument in system functions Fujii Masao <masao.fujii@gmail.com>
0 siblings, 1 reply; 31+ messages in thread
From: Tom Lane @ 2026-07-03 14:15 UTC (permalink / raw)
To: Fujii Masao <masao.fujii@gmail.com>; +Cc: Tristan Partin <tristan@partin.io>; Mark Wong <markwkm@gmail.com>; pgsql-hackers@lists.postgresql.org
Fujii Masao <masao.fujii@gmail.com> writes:
> I have one question, though.
> Suppose a user executes GRANT or REVOKE on pg_get_ruledef(oid), then
> creates a dump with pg_dump. If that dump is restored into a newer
> server where these patches have been applied, the restore would fail
> because pg_get_ruledef(oid) no longer exists.
> Is that acceptable (this means that users need to handle the restore
> failure), or should pg_dump handle this case specially?
I wouldn't blink an eye at that. There's no obvious use-case for
someone to mess with the permissions on that function. Even
if there were, I don't think it'd be reasonable for pg_dump to
try to patch it up. (I'm not sure that pg_dump would dump such
grants in the first place.)
regards, tom lane
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: updates for handling optional argument in system functions
2025-12-09 23:28 updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-02 18:36 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-07 22:26 ` Re: updates for handling optional argument in system functions Andreas Karlsson <andreas@proxel.se>
2026-04-07 23:42 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-07 23:51 ` Re: updates for handling optional argument in system functions Andreas Karlsson <andreas@proxel.se>
2026-04-08 18:10 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-06-05 20:14 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-06-05 21:04 ` Re: updates for handling optional argument in system functions Tristan Partin <tristan@partin.io>
2026-06-11 14:47 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-06-18 16:50 ` Re: updates for handling optional argument in system functions Tristan Partin <tristan@partin.io>
2026-07-03 13:59 ` Re: updates for handling optional argument in system functions Fujii Masao <masao.fujii@gmail.com>
2026-07-03 14:15 ` Re: updates for handling optional argument in system functions Tom Lane <tgl@sss.pgh.pa.us>
@ 2026-07-03 15:01 ` Fujii Masao <masao.fujii@gmail.com>
0 siblings, 0 replies; 31+ messages in thread
From: Fujii Masao @ 2026-07-03 15:01 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Tristan Partin <tristan@partin.io>; Mark Wong <markwkm@gmail.com>; pgsql-hackers@lists.postgresql.org
On Fri, Jul 3, 2026 at 11:15 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> Fujii Masao <masao.fujii@gmail.com> writes:
> > I have one question, though.
>
> > Suppose a user executes GRANT or REVOKE on pg_get_ruledef(oid), then
> > creates a dump with pg_dump. If that dump is restored into a newer
> > server where these patches have been applied, the restore would fail
> > because pg_get_ruledef(oid) no longer exists.
>
> > Is that acceptable (this means that users need to handle the restore
> > failure), or should pg_dump handle this case specially?
>
> I wouldn't blink an eye at that. There's no obvious use-case for
> someone to mess with the permissions on that function. Even
> if there were, I don't think it'd be reasonable for pg_dump to
> try to patch it up. (I'm not sure that pg_dump would dump such
> grants in the first place.)
pg_dump seems to dump such grants. For example:
$ createuser foo
$ psql -c "REVOKE ALL ON FUNCTION pg_get_ruledef(oid) FROM public"
REVOKE
$ psql -c "GRANT ALL ON FUNCTION pg_get_ruledef(oid) TO foo"
GRANT
$ pg_dump | grep pg_get_ruledef
-- Name: FUNCTION pg_get_ruledef(oid); Type: ACL; Schema:
pg_catalog; Owner: postgres
REVOKE ALL ON FUNCTION pg_catalog.pg_get_ruledef(oid) FROM PUBLIC;
GRANT ALL ON FUNCTION pg_catalog.pg_get_ruledef(oid) TO foo;
My concern was simply that restoring such a dump into a newer server
could fail because the single-argument function like pg_get_ruledef(oid)
no longer exists. This could affect not only GRANT/REVOKE, but also
commands such as ALTER FUNCTION and COMMENT, etc.
So I just asked that question.
If we agree that these are fairly unlikely use cases, so no special
handling for such restore failures is necessary, I'm ok with that.
Regards,
--
Fujii Masao
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: updates for handling optional argument in system functions
2025-12-09 23:28 updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-02 18:36 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-07 22:26 ` Re: updates for handling optional argument in system functions Andreas Karlsson <andreas@proxel.se>
2026-04-07 23:42 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-07 23:51 ` Re: updates for handling optional argument in system functions Andreas Karlsson <andreas@proxel.se>
2026-04-08 18:10 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-06-05 20:14 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-06-05 21:04 ` Re: updates for handling optional argument in system functions Tristan Partin <tristan@partin.io>
2026-06-11 14:47 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
@ 2026-09-12 00:22 ` Mark Wong <markwkm@gmail.com>
2026-09-15 16:33 ` Re: updates for handling optional argument in system functions Rui Zhao <zhaorui126@gmail.com>
1 sibling, 1 reply; 31+ messages in thread
From: Mark Wong @ 2026-09-12 00:22 UTC (permalink / raw)
To: Tristan Partin <tristan@partin.io>; +Cc: pgsql-hackers@lists.postgresql.org
Hi everyone,
I caught a rebase was needed, so v9 attached.
Regards,
Mark
--
Mark Wong
pgEdge: https://www.pgedge.com
From fc0bbec7d361d2616a7b3144b6a0fb84be7c6ba5 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Mon, 8 Dec 2025 15:41:07 -0800
Subject: [PATCH v9 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 | 8 +++-----
2 files changed, 3 insertions(+), 23 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index f42263bf9c9..4a9f4b13d42 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -564,24 +564,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 74d386b868b..3451c18b080 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,9 +3975,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',
@@ -8642,9 +8639,10 @@
prosrc => 'macaddr8_send' },
# System-view support functions with pretty-print option
-{ oid => '2504', descr => 'source text of a rule with pretty-print option',
+{ oid => '2504', descr => 'source text of a rule',
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.55.0
From be6697728cf2fc7cfc9874f4e5fda454aaf0df97 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 09:33:21 -0800
Subject: [PATCH v9 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 | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 4a9f4b13d42..ad7d167ce91 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -664,25 +664,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);
@@ -722,31 +703,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 3451c18b080..e81e7ef57b2 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,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' },
@@ -8644,15 +8637,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
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',
+ descr => 'select statement of a view',
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.55.0
From 47b2423743c39315c08fc04b16eaceec6203405d Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 10:02:15 -0800
Subject: [PATCH v9 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 | 8 +++-----
2 files changed, 3 insertions(+), 25 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index ad7d167ce91..99634eade70 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -1120,26 +1120,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 e81e7ef57b2..d5cee487446 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3978,9 +3978,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',
@@ -8654,9 +8651,10 @@
prorettype => 'text', proargtypes => 'oid int4',
prosrc => 'pg_get_viewdef_wrap' },
{ oid => '2507',
- descr => 'index description (full create statement or single expression) with pretty-print option',
+ descr => 'index description',
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.55.0
From 0dd18d7bb7ad43e32042f59b21709eb035b514c7 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 10:59:41 -0800
Subject: [PATCH v9 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 | 8 +++-----
2 files changed, 3 insertions(+), 22 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 99634eade70..42a1abfd25f 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -2067,23 +2067,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 d5cee487446..ea46539b36a 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -4000,9 +4000,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' },
@@ -8655,9 +8652,10 @@
proname => 'pg_get_indexdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid int4 bool', proargnames => '{index,column,pretty}',
proargdefaults => '{0,false}', prosrc => 'pg_get_indexdef' },
-{ oid => '2508', descr => 'constraint description with pretty-print option',
+{ oid => '2508', descr => 'constraint description',
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 => '6501', descr => 'get DDL to recreate a role',
proname => 'pg_get_role_ddl', prorows => '10', proretset => 't',
provolatile => 's', pronargdefaults => '2', prorettype => 'text',
--
2.55.0
From be9a1802ac1a5b0a82f4451de67412482746eb43 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 11:17:56 -0800
Subject: [PATCH v9 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 | 9 ++++-----
3 files changed, 7 insertions(+), 24 deletions(-)
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 8dc70bfa0f1..4ca83856d62 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -18119,8 +18119,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 42a1abfd25f..7169ac6687a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -2579,23 +2579,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 ea46539b36a..a73e209f140 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -4000,9 +4000,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' },
@@ -8679,9 +8676,11 @@
proargnames => '{database,pretty,owner,tablespace}',
proargdefaults => '{false,true,true}', prosrc => 'pg_get_database_ddl' },
{ oid => '2509',
- descr => 'deparse an encoded expression with pretty-print option',
+ descr => 'deparse an encoded expression',
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.55.0
From 5897b6e49c9aca7578da118852041cfb01871501 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 11:51:39 -0800
Subject: [PATCH v9 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 | 8 +++-----
2 files changed, 3 insertions(+), 19 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 7169ac6687a..b8fd387deed 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -813,20 +813,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 a73e209f140..dbf337f6c8c 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3997,9 +3997,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' },
@@ -8714,9 +8711,10 @@
proallargtypes => '{text,text,interval,bool}', proargmodes => '{o,o,o,o}',
proargnames => '{name,abbrev,utc_offset,is_dst}',
prosrc => 'pg_timezone_names' },
-{ oid => '2730', descr => 'trigger description with pretty-print option',
+{ oid => '2730', descr => 'trigger description',
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.55.0
Attachments:
[text/plain] v9-0001-Handle-pg_get_ruledef-default-args-in-system_func.patch (2.5K, ../../aqSbTlQYiC2_FEVs@localhost/2-v9-0001-Handle-pg_get_ruledef-default-args-in-system_func.patch)
download | inline diff:
From fc0bbec7d361d2616a7b3144b6a0fb84be7c6ba5 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Mon, 8 Dec 2025 15:41:07 -0800
Subject: [PATCH v9 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 | 8 +++-----
2 files changed, 3 insertions(+), 23 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index f42263bf9c9..4a9f4b13d42 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -564,24 +564,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 74d386b868b..3451c18b080 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,9 +3975,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',
@@ -8642,9 +8639,10 @@
prosrc => 'macaddr8_send' },
# System-view support functions with pretty-print option
-{ oid => '2504', descr => 'source text of a rule with pretty-print option',
+{ oid => '2504', descr => 'source text of a rule',
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.55.0
[text/plain] v9-0002-Handle-pg_get_viewdef-default-args-in-system_func.patch (4.0K, ../../aqSbTlQYiC2_FEVs@localhost/3-v9-0002-Handle-pg_get_viewdef-default-args-in-system_func.patch)
download | inline diff:
From be6697728cf2fc7cfc9874f4e5fda454aaf0df97 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 09:33:21 -0800
Subject: [PATCH v9 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 | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 4a9f4b13d42..ad7d167ce91 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -664,25 +664,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);
@@ -722,31 +703,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 3451c18b080..e81e7ef57b2 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,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' },
@@ -8644,15 +8637,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
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',
+ descr => 'select statement of a view',
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.55.0
[text/plain] v9-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch (2.8K, ../../aqSbTlQYiC2_FEVs@localhost/4-v9-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch)
download | inline diff:
From 47b2423743c39315c08fc04b16eaceec6203405d Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 10:02:15 -0800
Subject: [PATCH v9 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 | 8 +++-----
2 files changed, 3 insertions(+), 25 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index ad7d167ce91..99634eade70 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -1120,26 +1120,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 e81e7ef57b2..d5cee487446 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3978,9 +3978,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',
@@ -8654,9 +8651,10 @@
prorettype => 'text', proargtypes => 'oid int4',
prosrc => 'pg_get_viewdef_wrap' },
{ oid => '2507',
- descr => 'index description (full create statement or single expression) with pretty-print option',
+ descr => 'index description',
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.55.0
[text/plain] v9-0004-Handle-pg_get_constraintdef-default-args-in-syste.patch (2.8K, ../../aqSbTlQYiC2_FEVs@localhost/5-v9-0004-Handle-pg_get_constraintdef-default-args-in-syste.patch)
download | inline diff:
From 0dd18d7bb7ad43e32042f59b21709eb035b514c7 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 10:59:41 -0800
Subject: [PATCH v9 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 | 8 +++-----
2 files changed, 3 insertions(+), 22 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 99634eade70..42a1abfd25f 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -2067,23 +2067,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 d5cee487446..ea46539b36a 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -4000,9 +4000,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' },
@@ -8655,9 +8652,10 @@
proname => 'pg_get_indexdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid int4 bool', proargnames => '{index,column,pretty}',
proargdefaults => '{0,false}', prosrc => 'pg_get_indexdef' },
-{ oid => '2508', descr => 'constraint description with pretty-print option',
+{ oid => '2508', descr => 'constraint description',
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 => '6501', descr => 'get DDL to recreate a role',
proname => 'pg_get_role_ddl', prorows => '10', proretset => 't',
provolatile => 's', pronargdefaults => '2', prorettype => 'text',
--
2.55.0
[text/plain] v9-0005-Handle-pg_get_expr-default-args-in-system_functio.patch (3.5K, ../../aqSbTlQYiC2_FEVs@localhost/6-v9-0005-Handle-pg_get_expr-default-args-in-system_functio.patch)
download | inline diff:
From be9a1802ac1a5b0a82f4451de67412482746eb43 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 11:17:56 -0800
Subject: [PATCH v9 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 | 9 ++++-----
3 files changed, 7 insertions(+), 24 deletions(-)
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 8dc70bfa0f1..4ca83856d62 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -18119,8 +18119,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 42a1abfd25f..7169ac6687a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -2579,23 +2579,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 ea46539b36a..a73e209f140 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -4000,9 +4000,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' },
@@ -8679,9 +8676,11 @@
proargnames => '{database,pretty,owner,tablespace}',
proargdefaults => '{false,true,true}', prosrc => 'pg_get_database_ddl' },
{ oid => '2509',
- descr => 'deparse an encoded expression with pretty-print option',
+ descr => 'deparse an encoded expression',
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.55.0
[text/plain] v9-0006-Handle-pg_get_triggerdef-default-args-in-system_f.patch (2.5K, ../../aqSbTlQYiC2_FEVs@localhost/7-v9-0006-Handle-pg_get_triggerdef-default-args-in-system_f.patch)
download | inline diff:
From 5897b6e49c9aca7578da118852041cfb01871501 Mon Sep 17 00:00:00 2001
From: Mark Wong <markwkm@gmail.com>
Date: Tue, 9 Dec 2025 11:51:39 -0800
Subject: [PATCH v9 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 | 8 +++-----
2 files changed, 3 insertions(+), 19 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 7169ac6687a..b8fd387deed 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -813,20 +813,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 a73e209f140..dbf337f6c8c 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3997,9 +3997,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' },
@@ -8714,9 +8711,10 @@
proallargtypes => '{text,text,interval,bool}', proargmodes => '{o,o,o,o}',
proargnames => '{name,abbrev,utc_offset,is_dst}',
prosrc => 'pg_timezone_names' },
-{ oid => '2730', descr => 'trigger description with pretty-print option',
+{ oid => '2730', descr => 'trigger description',
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.55.0
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: updates for handling optional argument in system functions
2025-12-09 23:28 updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-02 18:36 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-07 22:26 ` Re: updates for handling optional argument in system functions Andreas Karlsson <andreas@proxel.se>
2026-04-07 23:42 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-07 23:51 ` Re: updates for handling optional argument in system functions Andreas Karlsson <andreas@proxel.se>
2026-04-08 18:10 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-06-05 20:14 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-06-05 21:04 ` Re: updates for handling optional argument in system functions Tristan Partin <tristan@partin.io>
2026-06-11 14:47 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-09-12 00:22 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
@ 2026-09-15 16:33 ` Rui Zhao <zhaorui126@gmail.com>
2026-09-22 21:48 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
0 siblings, 1 reply; 31+ messages in thread
From: Rui Zhao @ 2026-09-15 16:33 UTC (permalink / raw)
To: Mark Wong <markwkm@gmail.com>; +Cc: Tristan Partin <tristan@partin.io>; pgsql-hackers@lists.postgresql.org
Hi Mark,
v9 applies cleanly on current master (f7700080dc4), and make check, the
TAP suites under src/bin and contrib check pass here. No objections to
the code; what follows is what I verified and a few small things.
1. Every existing call form behaves the same as before. I ran one
script against an unpatched build and a v9 build of the same base
commit: the one-, two- and three-argument calls of the six functions
(pg_get_viewdef by name, by oid and with wrap_column included, plus the
unknown-literal and NULL cases and the "is not unique" error for
pg_get_viewdef(oid, NULL)), pg_indexes/pg_rules/pg_views,
information_schema.columns and check_constraints, \d output and
schema-only pg_dump output are byte-identical between the two builds.
Views defined over the one-argument forms deparse identically as well:
the parser doesn't store default arguments in the FuncExpr, so
pg_get_viewdef of such a view still prints pg_get_viewdef(c.oid). What
is new is pg_get_indexdef(index, column) with just two arguments, and
named notation such as pg_get_viewdef(view => 'v', pretty => true).
2. pg_upgrade from an unpatched cluster works for views over these
functions: afterwards the view trees reference pg_proc OIDs
2504/2505/2506 instead of 1573/1640/1641, and the views return the same
rows as before the upgrade. For the case Fujii described, a GRANT on
pg_get_ruledef(oid) in the old cluster, pg_upgrade --check reports
"Clusters are compatible" and the upgrade then fails in the restore
step:
pg_restore: error: could not execute query: ERROR: function
pg_catalog.pg_get_ruledef(oid) does not exist
Command was: REVOKE ALL ON FUNCTION
"pg_catalog"."pg_get_ruledef"("oid") FROM PUBLIC;
pg_dump only emits ACLs for pg_catalog functions that differ from
pg_init_privs, so this needs someone to have changed the privileges of
one of the removed signatures.
3. Smaller things:
* The six commit subjects still say "in system_functions.sql"; since v4
the patches set proargdefaults in pg_proc.dat and don't touch
system_functions.sql.
* reformat_dat_file.pl moves descr back onto the "{ oid =>" line for
2505, 2506, 2507 and 2509 now that the descriptions are shorter. (It
also reformats uuid_larger/uuid_smaller, but that is pre-existing on
master.)
* func-info.sgml has pg_get_indexdef ( index oid [, column integer,
pretty boolean ] ); with the defaults, column can be given without
pretty, so [, column integer [, pretty boolean ] ] would describe it.
* For C callers: the _ext symbols go away and the fmgroids.h macros
lose their type suffixes (F_PG_GET_EXPR_PG_NODE_TREE_OID_BOOL becomes
F_PG_GET_EXPR). A DirectFunctionCall2(pg_get_expr, ...) in extension
code still compiles and then reads past the end of its
FunctionCallInfo, which is what the sanitizer caught in tablecmds.c
in v1.
Regards,
Rui
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: updates for handling optional argument in system functions
2025-12-09 23:28 updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-02 18:36 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-07 22:26 ` Re: updates for handling optional argument in system functions Andreas Karlsson <andreas@proxel.se>
2026-04-07 23:42 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-07 23:51 ` Re: updates for handling optional argument in system functions Andreas Karlsson <andreas@proxel.se>
2026-04-08 18:10 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-06-05 20:14 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-06-05 21:04 ` Re: updates for handling optional argument in system functions Tristan Partin <tristan@partin.io>
2026-06-11 14:47 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-09-12 00:22 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-09-15 16:33 ` Re: updates for handling optional argument in system functions Rui Zhao <zhaorui126@gmail.com>
@ 2026-09-22 21:48 ` Mark Wong <markwkm@gmail.com>
2026-09-25 16:43 ` Re: updates for handling optional argument in system functions Rui Zhao <zhaorui126@gmail.com>
0 siblings, 1 reply; 31+ messages in thread
From: Mark Wong @ 2026-09-22 21:48 UTC (permalink / raw)
To: Rui Zhao <zhaorui126@gmail.com>; +Cc: Tristan Partin <tristan@partin.io>; pgsql-hackers@lists.postgresql.org
Hi!
On Wed, Sep 16, 2026 at 12:33:18AM +0800, Rui Zhao wrote:
> Hi Mark,
>
> v9 applies cleanly on current master (f7700080dc4), and make check, the
> TAP suites under src/bin and contrib check pass here. No objections to
> the code; what follows is what I verified and a few small things.
>
> 1. Every existing call form behaves the same as before. I ran one
> script against an unpatched build and a v9 build of the same base
> commit: the one-, two- and three-argument calls of the six functions
> (pg_get_viewdef by name, by oid and with wrap_column included, plus the
> unknown-literal and NULL cases and the "is not unique" error for
> pg_get_viewdef(oid, NULL)), pg_indexes/pg_rules/pg_views,
> information_schema.columns and check_constraints, \d output and
> schema-only pg_dump output are byte-identical between the two builds.
> Views defined over the one-argument forms deparse identically as well:
> the parser doesn't store default arguments in the FuncExpr, so
> pg_get_viewdef of such a view still prints pg_get_viewdef(c.oid). What
> is new is pg_get_indexdef(index, column) with just two arguments, and
> named notation such as pg_get_viewdef(view => 'v', pretty => true).
>
> 2. pg_upgrade from an unpatched cluster works for views over these
> functions: afterwards the view trees reference pg_proc OIDs
> 2504/2505/2506 instead of 1573/1640/1641, and the views return the same
> rows as before the upgrade. For the case Fujii described, a GRANT on
> pg_get_ruledef(oid) in the old cluster, pg_upgrade --check reports
> "Clusters are compatible" and the upgrade then fails in the restore
> step:
>
> pg_restore: error: could not execute query: ERROR: function
> pg_catalog.pg_get_ruledef(oid) does not exist
> Command was: REVOKE ALL ON FUNCTION
> "pg_catalog"."pg_get_ruledef"("oid") FROM PUBLIC;
>
> pg_dump only emits ACLs for pg_catalog functions that differ from
> pg_init_privs, so this needs someone to have changed the privileges of
> one of the removed signatures.
Right. Do I understand correctly that this is going to be considered an
unusual and rare occurrence? That we will expect the user to manually
handle the privileges instead of having pg_upgrade recognize that.
> 3. Smaller things:
>
> * The six commit subjects still say "in system_functions.sql"; since v4
> the patches set proargdefaults in pg_proc.dat and don't touch
> system_functions.sql.
Oops, new version coming in an attempt to correct that.
> * reformat_dat_file.pl moves descr back onto the "{ oid =>" line for
> 2505, 2506, 2507 and 2509 now that the descriptions are shorter. (It
> also reformats uuid_larger/uuid_smaller, but that is pre-existing on
> master.)
>
> * func-info.sgml has pg_get_indexdef ( index oid [, column integer,
> pretty boolean ] ); with the defaults, column can be given without
> pretty, so [, column integer [, pretty boolean ] ] would describe it.
I think I fixed that now.
> * For C callers: the _ext symbols go away and the fmgroids.h macros
> lose their type suffixes (F_PG_GET_EXPR_PG_NODE_TREE_OID_BOOL becomes
> F_PG_GET_EXPR). A DirectFunctionCall2(pg_get_expr, ...) in extension
> code still compiles and then reads past the end of its
> FunctionCallInfo, which is what the sanitizer caught in tablecmds.c
> in v1.
I may need a reminder, or help understanding this better. I believe
nothing in the core code has been hard coded to use the generated
macros. I recognize that there may be other code that could use the
previous macros, but that would be situations where the code would have
been built against an older major version and we say in the docs
"Cautious users will want to test their client applications on the new
version before switching over fully..." in doc/src/sgml/runtime.sgml.
Am I misunderstanding?
In the meantime, I've attached v10.
Thanks for the review!
Regards,
Mark
--
Mark Wong
pgEdge: https://www.pgedge.com
Attachments:
[text/plain] v10-0001-Refactor-pg_get_ruledef-default-args-as-a-single.patch (0B, ../../arL3mPVtkeJQ6_g3@localhost/2-v10-0001-Refactor-pg_get_ruledef-default-args-as-a-single.patch)
download
^ permalink raw reply [nested|flat] 31+ messages in thread
* Re: updates for handling optional argument in system functions
2025-12-09 23:28 updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-02 18:36 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-07 22:26 ` Re: updates for handling optional argument in system functions Andreas Karlsson <andreas@proxel.se>
2026-04-07 23:42 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-04-07 23:51 ` Re: updates for handling optional argument in system functions Andreas Karlsson <andreas@proxel.se>
2026-04-08 18:10 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-06-05 20:14 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-06-05 21:04 ` Re: updates for handling optional argument in system functions Tristan Partin <tristan@partin.io>
2026-06-11 14:47 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-09-12 00:22 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2026-09-15 16:33 ` Re: updates for handling optional argument in system functions Rui Zhao <zhaorui126@gmail.com>
2026-09-22 21:48 ` Re: updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
@ 2026-09-25 16:43 ` Rui Zhao <zhaorui126@gmail.com>
0 siblings, 0 replies; 31+ messages in thread
From: Rui Zhao @ 2026-09-25 16:43 UTC (permalink / raw)
To: Mark Wong <markwkm@gmail.com>; +Cc: Tristan Partin <tristan@partin.io>; pgsql-hackers@lists.postgresql.org
Hi Mark,
I should have been clearer about points 1 and 2 in my last mail:
> 1. Every existing call form behaves the same as before.
>
> 2. pg_upgrade from an unpatched cluster works for views over these
> functions: afterwards the view trees reference pg_proc OIDs
> 2504/2505/2506 instead of 1573/1640/1641, and the views return the
> same rows as before the upgrade.
Those were confirmations that existing calls and views still work.
For the ACL failure later in point 2, I should have stated whether I
thought it needed special handling.
> Do I understand correctly that this is going to be considered an
> unusual and rare occurrence? That we will expect the user to manually
> handle the privileges instead of having pg_upgrade recognize that.
Yes, I think manual handling is reasonable here. I manually restored
the default privileges on pg_get_ruledef(oid) in the old cluster, then
reran pg_upgrade to v10. The upgrade completed.
> Am I misunderstanding?
I meant this as a reminder for developers, especially C extension
authors, when updating their code for the new major version. I'm not
asking you to preserve compatibility with the old C calls.
The macro changes will be caught when rebuilding, but an unchanged
DirectFunctionCall2(pg_get_expr, ...) still compiles with v10 headers;
I checked with -Werror. It needs the explicit third argument, just as
decompile_conbin() now passes BoolGetDatum(false) in
DirectFunctionCall3(). Recompiling alone doesn't fix that call.
I rebuilt and retested v10. LGTM.
One small comment remains: pg_get_indexdef() still says "In the extended
version, there is a colno argument as well as pretty bool." There is
only one version now, so that sentence could describe the arguments
without the "extended version" distinction.
Regards,
Rui
^ permalink raw reply [nested|flat] 31+ messages in thread
end of thread, other threads:[~2026-09-25 16:43 UTC | newest]
Thread overview: 31+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-12-09 23:28 updates for handling optional argument in system functions Mark Wong <markwkm@gmail.com>
2025-12-10 09:33 ` Daniel Gustafsson <daniel@yesql.se>
2026-01-20 18:15 ` Mark Wong <markwkm@gmail.com>
2026-01-21 08:45 ` Chao Li <li.evan.chao@gmail.com>
2026-01-30 00:15 ` Mark Wong <markwkm@gmail.com>
2026-02-18 21:56 ` Andreas Karlsson <andreas@proxel.se>
2026-02-26 19:43 ` Mark Wong <markwkm@gmail.com>
2026-03-03 16:23 ` Álvaro Herrera <alvherre@kurilemu.de>
2026-03-12 03:28 ` Mark Wong <markwkm@gmail.com>
2026-04-02 18:36 ` Mark Wong <markwkm@gmail.com>
2026-04-07 22:26 ` Andreas Karlsson <andreas@proxel.se>
2026-04-07 23:28 ` Andreas Karlsson <andreas@proxel.se>
2026-04-07 23:44 ` Mark Wong <markwkm@gmail.com>
2026-04-08 01:33 ` Chao Li <li.evan.chao@gmail.com>
2026-04-08 01:46 ` David G. Johnston <david.g.johnston@gmail.com>
2026-04-08 02:09 ` Chao Li <li.evan.chao@gmail.com>
2026-04-07 23:42 ` Mark Wong <markwkm@gmail.com>
2026-04-07 23:51 ` Andreas Karlsson <andreas@proxel.se>
2026-04-08 18:10 ` Mark Wong <markwkm@gmail.com>
2026-04-08 19:18 ` Andreas Karlsson <andreas@proxel.se>
2026-06-05 20:14 ` Mark Wong <markwkm@gmail.com>
2026-06-05 21:04 ` Tristan Partin <tristan@partin.io>
2026-06-11 14:47 ` Mark Wong <markwkm@gmail.com>
2026-06-18 16:50 ` Tristan Partin <tristan@partin.io>
2026-07-03 13:59 ` Fujii Masao <masao.fujii@gmail.com>
2026-07-03 14:15 ` Tom Lane <tgl@sss.pgh.pa.us>
2026-07-03 15:01 ` Fujii Masao <masao.fujii@gmail.com>
2026-09-12 00:22 ` Mark Wong <markwkm@gmail.com>
2026-09-15 16:33 ` Rui Zhao <zhaorui126@gmail.com>
2026-09-22 21:48 ` Mark Wong <markwkm@gmail.com>
2026-09-25 16:43 ` Rui Zhao <zhaorui126@gmail.com>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox