Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1x98Lg-00000001len-1ITn for pgsql-hackers@arkaria.postgresql.org; Tue, 22 Sep 2026 21:48:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1x98Lf-00000001nWn-1bus for pgsql-hackers@arkaria.postgresql.org; Tue, 22 Sep 2026 21:48:23 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1x98Lf-00000001nWf-06qK for pgsql-hackers@lists.postgresql.org; Tue, 22 Sep 2026 21:48:23 +0000 Received: from mail-dl2-x0f.google.com ([2607:f8b0:4864:38::f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1x98Lc-00000000lvC-0yL2 for pgsql-hackers@lists.postgresql.org; Tue, 22 Sep 2026 21:48:22 +0000 Received: by mail-dl2-x0f.google.com with SMTP id a92af1059eb24-14354475e6cso123288c88.0 for ; Tue, 22 Sep 2026 14:48:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790113697; x=1790718497; darn=lists.postgresql.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=ywbYHtR3btwqCSelo351zDQBwkjX69nV9J8WdDpeMBc=; b=cn3tkzrtOAxS4nAhHYDLhBQvESkYR96tBEp5G3p8Y5kIbmxk3OkxJVeGMppPQcTq0B /Y8Mvr9w8DpRFjDUlvH/0tEvvwUaepIvqx4c/6y5Byo2MhuLoNy95LD7eObB2UM4/V/3 CG3nPCOdXhnAZ6d1/p5tYW4qirlvSUsosnb1yp1DyO2l0fNvsq81eve1NvXx4fHU2tfi DPJAAQcF0Czfjn2Q7YTKiLfmk0LlhElrRkbJ+v2YQZaVeBEDArzZzKeGtqPLH2HuaU64 qSPB8B7Wzjkw1dt8w/geGGxbUGmG8Z2hGctwU6fsH5h1F2ZguVX6TdyFFAxTm4p3KHCZ Ocag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790113697; x=1790718497; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=ywbYHtR3btwqCSelo351zDQBwkjX69nV9J8WdDpeMBc=; b=DXoOTICaMRKhCeMktmeM0Ds0s3WxfZAeLmp1j3Q2IcLRMoUi3DUexBbSm/7J1klfUr EI3aZ03mETudEvbTM5Mq7IztpZntRmQjdRB2oYq8U7LCYEb/udhjy785j8m3BsTFCiuj jiw4xu9lD8o8BI7lCk/wBC3N7o+69HAUW+1lG2lu+q57k9GL4KcgXNeJr6Wq1kw1Lugp TV2Y16dXzhayRhB0m9KWGmSeofET61EfPkT3H6ScwhlvXRa/nR8QzrOOF0H0VT3o8Gfk lkm5ukukAPO2amTMY2Y5cYAWzrII5/fI33wGVsZHLPz84SSOBWRS5hEBbwACkoQTJJyP /6LQ== X-Forwarded-Encrypted: i=1; AKwUvBw5/rOa1qbKSTuO+f3lh45bzBFHV8DPFGv4IH09h1JPAtTv1I0L/GLoC0NVJVfA0FYeGNlvjmlUhINwRyDx@lists.postgresql.org X-Gm-Message-State: AFuF++lGZ5tRfurlnSYyrRe9jCpkr1HoVQ0y821lQITX2ZnxIhX5s9vs 3sCyzwhHV9J3C9bwnJKt75QzoH1r+1miB2StC/8DOaC7Fi4dsQtrcHEZ X-Gm-Gg: AYBFou3Jd4axa4T7S/Y9kImbynU1svgSLmVB/9oboe/4vqCov6mOgV73K8caqVuAywB 4NmG+J37h+iZH02j+NQXC9PgwsOOVtc+KKrdJqif3+CBueCCJaE/sJ+pRCKO51hZSyDiqaXIQ9V niKra7yksOGoVd/8KUQRbh2VsB76sYiL+9u4x5uXRf/aU2Nc7PvQ05S1MbDzxQOcsdFjAOgJU1U wmVtVx/TNKJZcsmi/iD+2T4QJfQT7KA2S/ljuX7uTQJmWxzp9w/kXSC1aFS/wuRUIqkWYrMw/2Y nXQTHRtHyEigr6P0zsXXOANcYmCdAQz6SFNPoUzUJLBjZN3B6nuS51S6MIPrPnrJmi+MfPbQKPe zYN67ePpE26/ipGRmZYtQXDibg4P38ZQvTsfPzolvvjFVSomJ4qCIbOOuox0YwlwKLXqzTWi4LV CmU1Ij09bwk6CReGjKeppV4jmGBOgArxkhrzhWdD3VikFd5+zOsaK55dw/5OBk0U6GzJ9MHBJVK pm13Zzj1o6zmJeEYkC/zRux X-Received: by 2002:a05:701b:4182:10b0:139:bf81:637f with SMTP id a92af1059eb24-144f90a7887mr828524c88.16.1790113697055; Tue, 22 Sep 2026 14:48:17 -0700 (PDT) Received: from localhost ([97.115.201.182]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-144f988342asm900041c88.11.2026.09.22.14.48.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2026 14:48:15 -0700 (PDT) Date: Tue, 22 Sep 2026 14:48:08 -0700 From: Mark Wong To: Rui Zhao Cc: Tristan Partin , pgsql-hackers@lists.postgresql.org Subject: Re: updates for handling optional argument in system functions Message-ID: References: <6de20662-36fd-4e00-a0b0-75d1e9deb5c8@proxel.se> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="FbpMEELeip/e4sJ1" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --FbpMEELeip/e4sJ1 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 --FbpMEELeip/e4sJ1 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v10-0001-Refactor-pg_get_ruledef-default-args-as-a-single.patch From 665cbf661548879247f7da9dfacf94a778b51667 Mon Sep 17 00:00:00 2001 From: Mark Wong Date: Mon, 8 Dec 2025 15:41:07 -0800 Subject: [PATCH v10 1/6] Refactor pg_get_ruledef default args as a single pg_proc.dat declaration 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 --FbpMEELeip/e4sJ1 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v10-0002-Refactor-pg_get_viewdef-default-args-as-a-single.patch From ef8475c69d1e037ef8d5a2c9cad3c658538ddc32 Mon Sep 17 00:00:00 2001 From: Mark Wong Date: Tue, 9 Dec 2025 09:33:21 -0800 Subject: [PATCH v10 2/6] Refactor pg_get_viewdef default args as a single pg_proc.dat declaration 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 | 19 +++++-------- 2 files changed, 6 insertions(+), 57 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..b405a028b57 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' }, @@ -8643,16 +8636,16 @@ proname => 'pg_get_ruledef', provolatile => 's', prorettype => 'text', proargtypes => 'oid bool', proargnames => '{rule,pretty}', proargdefaults => '{false}', prosrc => 'pg_get_ruledef' }, -{ oid => '2505', - descr => 'select statement of a view with pretty-print option', +{ oid => '2505', 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' }, -{ oid => '2506', - descr => 'select statement of a view with pretty-print option', + proargnames => '{view,pretty}', proargdefaults => '{false}', + prosrc => 'pg_get_viewdef_name' }, +{ oid => '2506', 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 --FbpMEELeip/e4sJ1 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v10-0003-Refactor-pg_get_indexdef-default-args-as-a-singl.patch From 3003cd20e08962b265daccb0d94653a0e0ddb0e9 Mon Sep 17 00:00:00 2001 From: Mark Wong Date: Tue, 9 Dec 2025 10:02:15 -0800 Subject: [PATCH v10 3/6] Refactor pg_get_indexdef default args as a single pg_proc.dat declaration Modernize pg_get_indexdef to use proargdefaults to handle the optional column and pretty argument. --- doc/src/sgml/func/func-info.sgml | 2 +- src/backend/utils/adt/ruleutils.c | 20 -------------------- src/include/catalog/pg_proc.dat | 9 +++------ 3 files changed, 4 insertions(+), 27 deletions(-) diff --git a/doc/src/sgml/func/func-info.sgml b/doc/src/sgml/func/func-info.sgml index e56c9a22c42..077826f00bb 100644 --- a/doc/src/sgml/func/func-info.sgml +++ b/doc/src/sgml/func/func-info.sgml @@ -1587,7 +1587,7 @@ SELECT pg_type_is_visible('myschema.widget'::regtype); pg_get_indexdef - pg_get_indexdef ( index oid , column integer, pretty boolean ) + pg_get_indexdef ( index oid , column integer , pretty boolean ) text 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 b405a028b57..6782b9b3195 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', @@ -8651,10 +8648,10 @@ proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r', 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', +{ oid => '2507', 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 --FbpMEELeip/e4sJ1 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v10-0004-Refactor-pg_get_constraintdef-default-args-as-a-.patch From f01ea2db354c71bef9fb5b8533111888e9443ade Mon Sep 17 00:00:00 2001 From: Mark Wong Date: Tue, 9 Dec 2025 10:59:41 -0800 Subject: [PATCH v10 4/6] Refactor pg_get_constraintdef default args as a single pg_proc.dat declaration 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 6782b9b3195..9b575606bcb 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' }, @@ -8652,9 +8649,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 --FbpMEELeip/e4sJ1 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v10-0005-Refactor-pg_get_expr-default-args-as-a-single-pg.patch From d75edfb70109c5cc141966ac9b2c33154b4aefe4 Mon Sep 17 00:00:00 2001 From: Mark Wong Date: Tue, 9 Dec 2025 11:17:56 -0800 Subject: [PATCH v10 5/6] Refactor pg_get_expr default args as a single pg_proc.dat declaration Modernize pg_get_expr to use proargdefaults to handle the optional pretty argument. That also means any direct function calls now need to set the pretty parameter. --- src/backend/commands/tablecmds.c | 5 +++-- src/backend/utils/adt/ruleutils.c | 17 ----------------- src/include/catalog/pg_proc.dat | 10 ++++------ 3 files changed, 7 insertions(+), 25 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 9b575606bcb..2aed6f6cc26 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' }, @@ -8675,10 +8672,11 @@ proargtypes => 'regdatabase bool bool bool', 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', +{ oid => '2509', 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 --FbpMEELeip/e4sJ1 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v10-0006-Refactor-pg_get_triggerdef-default-args-as-a-sin.patch From 2003dc48c2c613cd9ff378888529e451a5eba77d Mon Sep 17 00:00:00 2001 From: Mark Wong Date: Tue, 9 Dec 2025 11:51:39 -0800 Subject: [PATCH v10 6/6] Refactor pg_get_triggerdef default args as a single pg_proc.dat declaration 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 2aed6f6cc26..ffb42437e8f 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' }, @@ -8710,9 +8707,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 --FbpMEELeip/e4sJ1--