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 1xH5s4-00000002ouH-0jlu for pgsql-hackers@arkaria.postgresql.org; Wed, 14 Oct 2026 20:46:44 +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 1xH5s2-00000005Kpq-2WKa for pgsql-hackers@arkaria.postgresql.org; Wed, 14 Oct 2026 20:46:42 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xH5s1-00000005Kph-3wq5 for pgsql-hackers@lists.postgresql.org; Wed, 14 Oct 2026 20:46:42 +0000 Received: from mail-dy1-x1335.google.com ([2607:f8b0:4864:20::1335]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1xH5ry-000000022Mt-3xe4 for pgsql-hackers@lists.postgresql.org; Wed, 14 Oct 2026 20:46:41 +0000 Received: by mail-dy1-x1335.google.com with SMTP id 5a478bee46e88-354ba08cfd1so7637424eec.1 for ; Wed, 14 Oct 2026 13:46:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1792010798; x=1792615598; 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=6xAmpv3K6E+P7OEKJxylarQ2eY9yDvIOp8cad6aJJq4=; b=hmFN9800hJvnkgqGjP1ssc168f/qyyi7mvqMAP5c2A/9ufq9s0WvTLs8TViDKr/wLZ HVCAGybtdCEQh6lVargpg/PiVz4hpdG8cWBii66XxcXf9gC3VA/TUiGFv7UhXxj732b1 0xy5LAXH279xY0wyxejbU+g1L6w53BTSXDlNGA3FP8+PC2hTtR1302RKx4eZC3mrnGA/ h9qchaAdgn4NuriSnNMB2xajXFv4jRxeYtj20Lx/Hc/FJT/Im8Wp8GdhTmgTkVV0xZaE 91/hZCxRtcjNeNyMX9zHyXKCMZE/6ixCXGWZvbhwQvz92pSQo68R9N+nv93SSI6Neka9 rfYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792010798; x=1792615598; 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=6xAmpv3K6E+P7OEKJxylarQ2eY9yDvIOp8cad6aJJq4=; b=nRZQpoRKZecx8inFrOo/6LiNF4is77H1IUtm4JhDstv4LrZxvYmsBsSN3V7jRHBGDA jDwbid47/bP/N1auqlH9/q5NT9qB1jsmwyNy7F7hMoj6dLGLbg63jp5gNd8XDTY99Q5+ Rkowcqo1T6U+1c3IuBTQaU9ocP1fOrbfcn1bTRRu1Kw0XKmmmD3BsmKqWvvAbamB7uO2 1xa21ex8pqSVm3pK8mdjuQt6nDFYS+tsVNQqBphizKOJu39+kC+IknDyh3cNk4F9XdDj 5NRGN2O1Al+84NcjrU0eMSJNB81u3BwRDMoQlu23UI8qiiG+EarC01PwORoNnNs5K32Q Qltw== X-Forwarded-Encrypted: i=1; AKwUvBzqJShuDDS+H6ic9hVybrPkujy0kEDhw5jASZVwGceqkmvLRLd4ha2Lu0qCeSsuHLAH59/8Fnroef+0rIZM@lists.postgresql.org X-Gm-Message-State: AFq9FYIjAx6AXiFGyvzGn4SEa6lQN7cju9IIfwY05jreTyxrcfctrw6L xjnec4ANC8PZVO74+9N7ZgwhVEq7W3yOGrdAFET/nRFTb74QZ7+X2qqi X-Gm-Gg: AYBFou3GhfvsVp2EUoIwMSt+xhVJGhPkkv9M5Ov4/pGthRCWLSfMMIkIxDBwfBMlUTg F/o/cOgwslLn/+22UZehNT0oI++scgZQf8l5H95OISDCNDnqaAAFezFuPZRuhb8x7wpzKz+ZWRp dxpJi8L7zdGfrYiev7gyzmTLTfefO0cZ924rypv1oRHP5uIsMxjPIaoxUlGA7pQDMUy4P1xizHo rcVzS3CrRa7LG4JXwETCafkVhtYibuHDGzWTx+bE/53zzC+M1M/heibFx2NSFx6mFzpoYJSNSbl qnU3jQlmw3j3xeIr8zUvlFUyCr2uofeK5Jsh0Yp0nePsciuqM0Qc5KVy23g9XpbCBfq3/WFBcqn piFSUVLvhDDaLjd36HI/tLeUUAAb+RsKL5uQxvjlzhLF6HWwA7gRSm08RphVptVVN+g8naCw1+u fW0wuiW77S1LfvUscAceh96OiepKIRYIl7xEwptOYsUYtxEvozYsZ8AZY8rc+MhqeVpf4uMe+Zg SaZa+7b57MIyOjBkAXnMlWU X-Received: by 2002:a05:693c:88c7:10b0:359:2729:1797 with SMTP id 5a478bee46e88-35927292f58mr16656475eec.30.1792010797791; Wed, 14 Oct 2026 13:46:37 -0700 (PDT) Received: from localhost ([97.115.201.182]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-35ca33b4065sm19285923eec.4.2026.10.14.13.46.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Oct 2026 13:46:36 -0700 (PDT) Date: Wed, 14 Oct 2026 13:46:33 -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: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="mgNVB9nLVw/pp9oJ" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --mgNVB9nLVw/pp9oJ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi! On Sat, Sep 26, 2026 at 12:43:19AM +0800, Rui Zhao wrote: > 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. Ah, understood now. > 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. I've shortened that to now read: There is a colno argument as well as an optional pretty bool. I've attached a v10.1 series. Thanks! Regards, Mark -- Mark Wong pgEdge: https://www.pgedge.com --mgNVB9nLVw/pp9oJ Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v10.1-0001-Refactor-pg_get_ruledef-default-args-as-a-sing.patch From 73e24ab759eb951aee23736756e4758bcdd2855d Mon Sep 17 00:00:00 2001 From: Mark Wong Date: Mon, 8 Dec 2025 15:41:07 -0800 Subject: [PATCH v10.1 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 5e8e1683db0..5a25f474444 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -561,24 +561,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 5e4c9e503f8..1119b55ca40 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', @@ -8643,9 +8640,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 --mgNVB9nLVw/pp9oJ Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v10.1-0002-Refactor-pg_get_viewdef-default-args-as-a-sing.patch From 5891b5987c4e2a63d6de2d68af514619a495a59e Mon Sep 17 00:00:00 2001 From: Mark Wong Date: Tue, 9 Dec 2025 09:33:21 -0800 Subject: [PATCH v10.1 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 5a25f474444..3f6e5334f78 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -661,25 +661,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); @@ -719,31 +700,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 1119b55ca40..aa13cb2cebd 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,16 +8637,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 --mgNVB9nLVw/pp9oJ Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v10.1-0003-Refactor-pg_get_indexdef-default-args-as-a-sin.patch From 9aab88bfcb815e96ad5804cc118b685f59244af6 Mon Sep 17 00:00:00 2001 From: Mark Wong Date: Tue, 9 Dec 2025 10:02:15 -0800 Subject: [PATCH v10.1 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 | 22 +--------------------- src/include/catalog/pg_proc.dat | 9 +++------ 3 files changed, 5 insertions(+), 28 deletions(-) diff --git a/doc/src/sgml/func/func-info.sgml b/doc/src/sgml/func/func-info.sgml index 8c88865cda2..8407c6d3159 100644 --- a/doc/src/sgml/func/func-info.sgml +++ b/doc/src/sgml/func/func-info.sgml @@ -1594,7 +1594,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 3f6e5334f78..f763ba592e7 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -1106,7 +1106,7 @@ pg_get_triggerdef_worker(Oid trigid, bool pretty) /* ---------- * pg_get_indexdef - Get the definition of an index * - * In the extended version, there is a colno argument as well as pretty bool. + * There is a colno argument as well as an optional pretty bool. * if colno == 0, we want a complete index definition. * if colno > 0, we only want the Nth index key's variable or expression. * @@ -1117,26 +1117,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 aa13cb2cebd..a60d00349c7 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', @@ -8652,10 +8649,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 --mgNVB9nLVw/pp9oJ Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v10.1-0004-Refactor-pg_get_constraintdef-default-args-as-.patch From 45f91b0232528813d8ab21c37f955aa11f415b9b Mon Sep 17 00:00:00 2001 From: Mark Wong Date: Tue, 9 Dec 2025 10:59:41 -0800 Subject: [PATCH v10.1 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 f763ba592e7..eba40278781 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -2064,23 +2064,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 a60d00349c7..a6a0c602d04 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' }, @@ -8653,9 +8650,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 --mgNVB9nLVw/pp9oJ Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v10.1-0005-Refactor-pg_get_expr-default-args-as-a-single-.patch From 7842d032aca05c9890d2accc7801a759d3ea8452 Mon Sep 17 00:00:00 2001 From: Mark Wong Date: Tue, 9 Dec 2025 11:17:56 -0800 Subject: [PATCH v10.1 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 93ad49e59fd..3fcb9025b9f 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -18133,8 +18133,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 eba40278781..d2380837f59 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -2576,23 +2576,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 a6a0c602d04..3bac39b8bce 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' }, @@ -8676,10 +8673,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 --mgNVB9nLVw/pp9oJ Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v10.1-0006-Refactor-pg_get_triggerdef-default-args-as-a-s.patch From 128f3ac16a7ef7187b3768895e64bf337c9e3dfb Mon Sep 17 00:00:00 2001 From: Mark Wong Date: Tue, 9 Dec 2025 11:51:39 -0800 Subject: [PATCH v10.1 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 d2380837f59..5c88b93aeb8 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -810,20 +810,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 3bac39b8bce..42bf91f8793 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' }, @@ -8711,9 +8708,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 --mgNVB9nLVw/pp9oJ--