agora inbox for pgsql-hackers@postgresql.org
help / color / mirror / Atom feedFrom: Mark Wong <markwkm@gmail.com>
To: pgsql-hackers@lists.postgresql.org
Subject: Re: updates for handling optional argument in system functions
Date: Tue, 20 Jan 2026 10:15:13 -0800
Message-ID: <aW_GMVYZqGnebYLE@o> (raw)
In-Reply-To: <aTiwu9o8vBkLreAL@ltdrgnflg2>
References: <aTiwu9o8vBkLreAL@ltdrgnflg2>
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
view thread (31+ messages) latest in thread
Message-ID: <aW_GMVYZqGnebYLE@o>
Permalink: ../aW_GMVYZqGnebYLE@o/
Also on: postgresql.org/message-id/aW_GMVYZqGnebYLE@o
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: markwkm@gmail.com, pgsql-hackers@lists.postgresql.org
Subject: Re: updates for handling optional argument in system functions
In-Reply-To: <aW_GMVYZqGnebYLE@o>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox