Thread

  1. [PATCH v3 4/7] Handle pg_get_indexdef default args in system_functions.sql

    Mark Wong <markwkm@gmail.com> — 2025-12-09T18:02:15Z

    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
    
    
    --zd8Z8rlPOcTi77n/
    Content-Type: text/x-diff; charset=us-ascii
    Content-Disposition: attachment;
    	filename="v3-0005-Handle-pg_get_constraintdef-default-args-in-syste.patch"