agora inbox for [email protected]help / color / mirror / Atom feed
[PATCH v20220916 07/13] DISCARD VARIABLES command 342+ messages / 3 participants [nested] [flat]
* [PATCH v20220916 07/13] DISCARD VARIABLES command @ 2022-04-04 22:13 [email protected] <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: [email protected] @ 2022-04-04 22:13 UTC (permalink / raw) --- src/backend/commands/discard.c | 6 ++++++ src/backend/parser/gram.y | 7 ++++++- src/backend/tcop/utility.c | 3 +++ src/include/nodes/parsenodes.h | 3 ++- src/include/tcop/cmdtaglist.h | 1 + 5 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/backend/commands/discard.c b/src/backend/commands/discard.c index c583539e0c..68fe550a71 100644 --- a/src/backend/commands/discard.c +++ b/src/backend/commands/discard.c @@ -19,6 +19,7 @@ #include "commands/discard.h" #include "commands/prepare.h" #include "commands/sequence.h" +#include "commands/session_variable.h" #include "utils/guc.h" #include "utils/portal.h" @@ -48,6 +49,10 @@ DiscardCommand(DiscardStmt *stmt, bool isTopLevel) ResetTempTableNamespace(); break; + case DISCARD_VARIABLES: + ResetSessionVariables(); + break; + default: elog(ERROR, "unrecognized DISCARD target: %d", stmt->target); } @@ -75,4 +80,5 @@ DiscardAll(bool isTopLevel) ResetPlanCache(); ResetTempTableNamespace(); ResetSequenceCaches(); + ResetSessionVariables(); } diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 1059a5c865..542be13a40 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -2024,7 +2024,12 @@ DiscardStmt: n->target = DISCARD_SEQUENCES; $$ = (Node *) n; } - + | DISCARD VARIABLES + { + DiscardStmt *n = makeNode(DiscardStmt); + n->target = DISCARD_VARIABLES; + $$ = (Node *) n; + } ; diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index d267cea0e1..8fbccd1db6 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -2952,6 +2952,9 @@ CreateCommandTag(Node *parsetree) case DISCARD_SEQUENCES: tag = CMDTAG_DISCARD_SEQUENCES; break; + case DISCARD_VARIABLES: + tag = CMDTAG_DISCARD_VARIABLES; + break; default: tag = CMDTAG_UNKNOWN; } diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 323354ea16..6d0bf1eba5 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -3568,7 +3568,8 @@ typedef enum DiscardMode DISCARD_ALL, DISCARD_PLANS, DISCARD_SEQUENCES, - DISCARD_TEMP + DISCARD_TEMP, + DISCARD_VARIABLES } DiscardMode; typedef struct DiscardStmt diff --git a/src/include/tcop/cmdtaglist.h b/src/include/tcop/cmdtaglist.h index 357989b52f..09bd4d467f 100644 --- a/src/include/tcop/cmdtaglist.h +++ b/src/include/tcop/cmdtaglist.h @@ -135,6 +135,7 @@ PG_CMDTAG(CMDTAG_DISCARD_ALL, "DISCARD ALL", false, false, false) PG_CMDTAG(CMDTAG_DISCARD_PLANS, "DISCARD PLANS", false, false, false) PG_CMDTAG(CMDTAG_DISCARD_SEQUENCES, "DISCARD SEQUENCES", false, false, false) PG_CMDTAG(CMDTAG_DISCARD_TEMP, "DISCARD TEMP", false, false, false) +PG_CMDTAG(CMDTAG_DISCARD_VARIABLES, "DISCARD VARIABLES", false, false, false) PG_CMDTAG(CMDTAG_DO, "DO", false, false, false) PG_CMDTAG(CMDTAG_DROP_ACCESS_METHOD, "DROP ACCESS METHOD", true, false, false) PG_CMDTAG(CMDTAG_DROP_AGGREGATE, "DROP AGGREGATE", true, false, false) -- 2.37.0 --w2in66fnadvggvsb Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v20220916-0008-enhancing-psql-for-session-variables.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH 05/11] DISCARD VARIABLES command @ 2022-04-04 22:13 [email protected] <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: [email protected] @ 2022-04-04 22:13 UTC (permalink / raw) --- src/backend/commands/discard.c | 6 ++++++ src/backend/parser/gram.y | 7 ++++++- src/backend/tcop/utility.c | 3 +++ src/include/nodes/parsenodes.h | 3 ++- src/include/tcop/cmdtaglist.h | 1 + 5 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/backend/commands/discard.c b/src/backend/commands/discard.c index c583539e0c..68fe550a71 100644 --- a/src/backend/commands/discard.c +++ b/src/backend/commands/discard.c @@ -19,6 +19,7 @@ #include "commands/discard.h" #include "commands/prepare.h" #include "commands/sequence.h" +#include "commands/session_variable.h" #include "utils/guc.h" #include "utils/portal.h" @@ -48,6 +49,10 @@ DiscardCommand(DiscardStmt *stmt, bool isTopLevel) ResetTempTableNamespace(); break; + case DISCARD_VARIABLES: + ResetSessionVariables(); + break; + default: elog(ERROR, "unrecognized DISCARD target: %d", stmt->target); } @@ -75,4 +80,5 @@ DiscardAll(bool isTopLevel) ResetPlanCache(); ResetTempTableNamespace(); ResetSequenceCaches(); + ResetSessionVariables(); } diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 2b57daa264..745f2cbbf6 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -2027,7 +2027,12 @@ DiscardStmt: n->target = DISCARD_SEQUENCES; $$ = (Node *) n; } - + | DISCARD VARIABLES + { + DiscardStmt *n = makeNode(DiscardStmt); + n->target = DISCARD_VARIABLES; + $$ = (Node *) n; + } ; diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index 724b74acb5..6c81f12dc7 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -2952,6 +2952,9 @@ CreateCommandTag(Node *parsetree) case DISCARD_SEQUENCES: tag = CMDTAG_DISCARD_SEQUENCES; break; + case DISCARD_VARIABLES: + tag = CMDTAG_DISCARD_VARIABLES; + break; default: tag = CMDTAG_UNKNOWN; } diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 52b2a037f6..c421b92816 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -3568,7 +3568,8 @@ typedef enum DiscardMode DISCARD_ALL, DISCARD_PLANS, DISCARD_SEQUENCES, - DISCARD_TEMP + DISCARD_TEMP, + DISCARD_VARIABLES } DiscardMode; typedef struct DiscardStmt diff --git a/src/include/tcop/cmdtaglist.h b/src/include/tcop/cmdtaglist.h index 357989b52f..09bd4d467f 100644 --- a/src/include/tcop/cmdtaglist.h +++ b/src/include/tcop/cmdtaglist.h @@ -135,6 +135,7 @@ PG_CMDTAG(CMDTAG_DISCARD_ALL, "DISCARD ALL", false, false, false) PG_CMDTAG(CMDTAG_DISCARD_PLANS, "DISCARD PLANS", false, false, false) PG_CMDTAG(CMDTAG_DISCARD_SEQUENCES, "DISCARD SEQUENCES", false, false, false) PG_CMDTAG(CMDTAG_DISCARD_TEMP, "DISCARD TEMP", false, false, false) +PG_CMDTAG(CMDTAG_DISCARD_VARIABLES, "DISCARD VARIABLES", false, false, false) PG_CMDTAG(CMDTAG_DO, "DO", false, false, false) PG_CMDTAG(CMDTAG_DROP_ACCESS_METHOD, "DROP ACCESS METHOD", true, false, false) PG_CMDTAG(CMDTAG_DROP_AGGREGATE, "DROP AGGREGATE", true, false, false) -- 2.37.2 --gcms4zhgklsgym3k Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v20220906-1-0006-enhancing-psql-for-session-variables.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v20220916 07/13] DISCARD VARIABLES command @ 2022-04-04 22:13 [email protected] <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: [email protected] @ 2022-04-04 22:13 UTC (permalink / raw) --- src/backend/commands/discard.c | 6 ++++++ src/backend/parser/gram.y | 7 ++++++- src/backend/tcop/utility.c | 3 +++ src/include/nodes/parsenodes.h | 3 ++- src/include/tcop/cmdtaglist.h | 1 + 5 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/backend/commands/discard.c b/src/backend/commands/discard.c index c583539e0c..68fe550a71 100644 --- a/src/backend/commands/discard.c +++ b/src/backend/commands/discard.c @@ -19,6 +19,7 @@ #include "commands/discard.h" #include "commands/prepare.h" #include "commands/sequence.h" +#include "commands/session_variable.h" #include "utils/guc.h" #include "utils/portal.h" @@ -48,6 +49,10 @@ DiscardCommand(DiscardStmt *stmt, bool isTopLevel) ResetTempTableNamespace(); break; + case DISCARD_VARIABLES: + ResetSessionVariables(); + break; + default: elog(ERROR, "unrecognized DISCARD target: %d", stmt->target); } @@ -75,4 +80,5 @@ DiscardAll(bool isTopLevel) ResetPlanCache(); ResetTempTableNamespace(); ResetSequenceCaches(); + ResetSessionVariables(); } diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 1059a5c865..542be13a40 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -2024,7 +2024,12 @@ DiscardStmt: n->target = DISCARD_SEQUENCES; $$ = (Node *) n; } - + | DISCARD VARIABLES + { + DiscardStmt *n = makeNode(DiscardStmt); + n->target = DISCARD_VARIABLES; + $$ = (Node *) n; + } ; diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index d267cea0e1..8fbccd1db6 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -2952,6 +2952,9 @@ CreateCommandTag(Node *parsetree) case DISCARD_SEQUENCES: tag = CMDTAG_DISCARD_SEQUENCES; break; + case DISCARD_VARIABLES: + tag = CMDTAG_DISCARD_VARIABLES; + break; default: tag = CMDTAG_UNKNOWN; } diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 323354ea16..6d0bf1eba5 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -3568,7 +3568,8 @@ typedef enum DiscardMode DISCARD_ALL, DISCARD_PLANS, DISCARD_SEQUENCES, - DISCARD_TEMP + DISCARD_TEMP, + DISCARD_VARIABLES } DiscardMode; typedef struct DiscardStmt diff --git a/src/include/tcop/cmdtaglist.h b/src/include/tcop/cmdtaglist.h index 357989b52f..09bd4d467f 100644 --- a/src/include/tcop/cmdtaglist.h +++ b/src/include/tcop/cmdtaglist.h @@ -135,6 +135,7 @@ PG_CMDTAG(CMDTAG_DISCARD_ALL, "DISCARD ALL", false, false, false) PG_CMDTAG(CMDTAG_DISCARD_PLANS, "DISCARD PLANS", false, false, false) PG_CMDTAG(CMDTAG_DISCARD_SEQUENCES, "DISCARD SEQUENCES", false, false, false) PG_CMDTAG(CMDTAG_DISCARD_TEMP, "DISCARD TEMP", false, false, false) +PG_CMDTAG(CMDTAG_DISCARD_VARIABLES, "DISCARD VARIABLES", false, false, false) PG_CMDTAG(CMDTAG_DO, "DO", false, false, false) PG_CMDTAG(CMDTAG_DROP_ACCESS_METHOD, "DROP ACCESS METHOD", true, false, false) PG_CMDTAG(CMDTAG_DROP_AGGREGATE, "DROP AGGREGATE", true, false, false) -- 2.37.0 --w2in66fnadvggvsb Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v20220916-0008-enhancing-psql-for-session-variables.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v20220922 07/13] DISCARD VARIABLES command @ 2022-04-04 22:13 [email protected] <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: [email protected] @ 2022-04-04 22:13 UTC (permalink / raw) --- src/backend/commands/discard.c | 6 ++++++ src/backend/parser/gram.y | 7 ++++++- src/backend/tcop/utility.c | 3 +++ src/include/nodes/parsenodes.h | 3 ++- src/include/tcop/cmdtaglist.h | 1 + 5 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/backend/commands/discard.c b/src/backend/commands/discard.c index c583539e0c..68fe550a71 100644 --- a/src/backend/commands/discard.c +++ b/src/backend/commands/discard.c @@ -19,6 +19,7 @@ #include "commands/discard.h" #include "commands/prepare.h" #include "commands/sequence.h" +#include "commands/session_variable.h" #include "utils/guc.h" #include "utils/portal.h" @@ -48,6 +49,10 @@ DiscardCommand(DiscardStmt *stmt, bool isTopLevel) ResetTempTableNamespace(); break; + case DISCARD_VARIABLES: + ResetSessionVariables(); + break; + default: elog(ERROR, "unrecognized DISCARD target: %d", stmt->target); } @@ -75,4 +80,5 @@ DiscardAll(bool isTopLevel) ResetPlanCache(); ResetTempTableNamespace(); ResetSequenceCaches(); + ResetSessionVariables(); } diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 9a45d94d9b..c1da4fb364 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -2024,7 +2024,12 @@ DiscardStmt: n->target = DISCARD_SEQUENCES; $$ = (Node *) n; } - + | DISCARD VARIABLES + { + DiscardStmt *n = makeNode(DiscardStmt); + n->target = DISCARD_VARIABLES; + $$ = (Node *) n; + } ; diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index d267cea0e1..8fbccd1db6 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -2952,6 +2952,9 @@ CreateCommandTag(Node *parsetree) case DISCARD_SEQUENCES: tag = CMDTAG_DISCARD_SEQUENCES; break; + case DISCARD_VARIABLES: + tag = CMDTAG_DISCARD_VARIABLES; + break; default: tag = CMDTAG_UNKNOWN; } diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 323354ea16..6d0bf1eba5 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -3568,7 +3568,8 @@ typedef enum DiscardMode DISCARD_ALL, DISCARD_PLANS, DISCARD_SEQUENCES, - DISCARD_TEMP + DISCARD_TEMP, + DISCARD_VARIABLES } DiscardMode; typedef struct DiscardStmt diff --git a/src/include/tcop/cmdtaglist.h b/src/include/tcop/cmdtaglist.h index 357989b52f..09bd4d467f 100644 --- a/src/include/tcop/cmdtaglist.h +++ b/src/include/tcop/cmdtaglist.h @@ -135,6 +135,7 @@ PG_CMDTAG(CMDTAG_DISCARD_ALL, "DISCARD ALL", false, false, false) PG_CMDTAG(CMDTAG_DISCARD_PLANS, "DISCARD PLANS", false, false, false) PG_CMDTAG(CMDTAG_DISCARD_SEQUENCES, "DISCARD SEQUENCES", false, false, false) PG_CMDTAG(CMDTAG_DISCARD_TEMP, "DISCARD TEMP", false, false, false) +PG_CMDTAG(CMDTAG_DISCARD_VARIABLES, "DISCARD VARIABLES", false, false, false) PG_CMDTAG(CMDTAG_DO, "DO", false, false, false) PG_CMDTAG(CMDTAG_DROP_ACCESS_METHOD, "DROP ACCESS METHOD", true, false, false) PG_CMDTAG(CMDTAG_DROP_AGGREGATE, "DROP AGGREGATE", true, false, false) -- 2.37.0 --z3ntqfnlkpftg4xg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v20220922-0008-enhancing-psql-for-session-variables.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH 05/11] DISCARD VARIABLES command @ 2022-04-04 22:13 [email protected] <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: [email protected] @ 2022-04-04 22:13 UTC (permalink / raw) --- src/backend/commands/discard.c | 6 ++++++ src/backend/parser/gram.y | 7 ++++++- src/backend/tcop/utility.c | 3 +++ src/include/nodes/parsenodes.h | 3 ++- src/include/tcop/cmdtaglist.h | 1 + 5 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/backend/commands/discard.c b/src/backend/commands/discard.c index c583539e0c..68fe550a71 100644 --- a/src/backend/commands/discard.c +++ b/src/backend/commands/discard.c @@ -19,6 +19,7 @@ #include "commands/discard.h" #include "commands/prepare.h" #include "commands/sequence.h" +#include "commands/session_variable.h" #include "utils/guc.h" #include "utils/portal.h" @@ -48,6 +49,10 @@ DiscardCommand(DiscardStmt *stmt, bool isTopLevel) ResetTempTableNamespace(); break; + case DISCARD_VARIABLES: + ResetSessionVariables(); + break; + default: elog(ERROR, "unrecognized DISCARD target: %d", stmt->target); } @@ -75,4 +80,5 @@ DiscardAll(bool isTopLevel) ResetPlanCache(); ResetTempTableNamespace(); ResetSequenceCaches(); + ResetSessionVariables(); } diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 2b57daa264..745f2cbbf6 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -2027,7 +2027,12 @@ DiscardStmt: n->target = DISCARD_SEQUENCES; $$ = (Node *) n; } - + | DISCARD VARIABLES + { + DiscardStmt *n = makeNode(DiscardStmt); + n->target = DISCARD_VARIABLES; + $$ = (Node *) n; + } ; diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index 724b74acb5..6c81f12dc7 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -2952,6 +2952,9 @@ CreateCommandTag(Node *parsetree) case DISCARD_SEQUENCES: tag = CMDTAG_DISCARD_SEQUENCES; break; + case DISCARD_VARIABLES: + tag = CMDTAG_DISCARD_VARIABLES; + break; default: tag = CMDTAG_UNKNOWN; } diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 52b2a037f6..c421b92816 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -3568,7 +3568,8 @@ typedef enum DiscardMode DISCARD_ALL, DISCARD_PLANS, DISCARD_SEQUENCES, - DISCARD_TEMP + DISCARD_TEMP, + DISCARD_VARIABLES } DiscardMode; typedef struct DiscardStmt diff --git a/src/include/tcop/cmdtaglist.h b/src/include/tcop/cmdtaglist.h index 357989b52f..09bd4d467f 100644 --- a/src/include/tcop/cmdtaglist.h +++ b/src/include/tcop/cmdtaglist.h @@ -135,6 +135,7 @@ PG_CMDTAG(CMDTAG_DISCARD_ALL, "DISCARD ALL", false, false, false) PG_CMDTAG(CMDTAG_DISCARD_PLANS, "DISCARD PLANS", false, false, false) PG_CMDTAG(CMDTAG_DISCARD_SEQUENCES, "DISCARD SEQUENCES", false, false, false) PG_CMDTAG(CMDTAG_DISCARD_TEMP, "DISCARD TEMP", false, false, false) +PG_CMDTAG(CMDTAG_DISCARD_VARIABLES, "DISCARD VARIABLES", false, false, false) PG_CMDTAG(CMDTAG_DO, "DO", false, false, false) PG_CMDTAG(CMDTAG_DROP_ACCESS_METHOD, "DROP ACCESS METHOD", true, false, false) PG_CMDTAG(CMDTAG_DROP_AGGREGATE, "DROP AGGREGATE", true, false, false) -- 2.37.2 --gcms4zhgklsgym3k Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v20220906-1-0006-enhancing-psql-for-session-variables.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v13 3/8] Row pattern recognition patch (rewriter). @ 2024-01-22 09:45 Tatsuo Ishii <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Tatsuo Ishii @ 2024-01-22 09:45 UTC (permalink / raw) --- src/backend/utils/adt/ruleutils.c | 90 +++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index 0b2a164057..baded88201 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -428,6 +428,10 @@ static void get_rule_groupingset(GroupingSet *gset, List *targetlist, bool omit_parens, deparse_context *context); static void get_rule_orderby(List *orderList, List *targetList, bool force_colno, deparse_context *context); +static void get_rule_pattern(List *patternVariable, List *patternRegexp, + bool force_colno, deparse_context *context); +static void get_rule_define(List *defineClause, List *patternVariables, + bool force_colno, deparse_context *context); static void get_rule_windowclause(Query *query, deparse_context *context); static void get_rule_windowspec(WindowClause *wc, List *targetList, deparse_context *context); @@ -6459,6 +6463,64 @@ get_rule_orderby(List *orderList, List *targetList, } } +/* + * Display a PATTERN clause. + */ +static void +get_rule_pattern(List *patternVariable, List *patternRegexp, + bool force_colno, deparse_context *context) +{ + StringInfo buf = context->buf; + const char *sep; + ListCell *lc_var, *lc_reg = list_head(patternRegexp); + + sep = ""; + appendStringInfoChar(buf, '('); + foreach(lc_var, patternVariable) + { + char *variable = strVal((String *) lfirst(lc_var)); + char *regexp = NULL; + + if (lc_reg != NULL) + { + regexp = strVal((String *) lfirst(lc_reg)); + lc_reg = lnext(patternRegexp, lc_reg); + } + + appendStringInfo(buf, "%s%s", sep, variable); + if (regexp != NULL) + appendStringInfoString(buf, regexp); + + sep = " "; + } + appendStringInfoChar(buf, ')'); +} + +/* + * Display a DEFINE clause. + */ +static void +get_rule_define(List *defineClause, List *patternVariables, + bool force_colno, deparse_context *context) +{ + StringInfo buf = context->buf; + const char *sep; + ListCell *lc_var, *lc_def; + + sep = " "; + Assert(list_length(patternVariables) == list_length(defineClause)); + + forboth(lc_var, patternVariables, lc_def, defineClause) + { + char *varName = strVal(lfirst(lc_var)); + TargetEntry *te = (TargetEntry *) lfirst(lc_def); + + appendStringInfo(buf, "%s%s AS ", sep, varName); + get_rule_expr((Node *) te->expr, context, false); + sep = ",\n "; + } +} + /* * Display a WINDOW clause. * @@ -6596,6 +6658,34 @@ get_rule_windowspec(WindowClause *wc, List *targetList, appendStringInfoString(buf, "EXCLUDE GROUP "); else if (wc->frameOptions & FRAMEOPTION_EXCLUDE_TIES) appendStringInfoString(buf, "EXCLUDE TIES "); + /* RPR */ + if (wc->rpSkipTo == ST_NEXT_ROW) + appendStringInfoString(buf, "\n AFTER MATCH SKIP TO NEXT ROW "); + else if (wc->rpSkipTo == ST_PAST_LAST_ROW) + appendStringInfoString(buf, "\n AFTER MATCH SKIP PAST LAST ROW "); + else if (wc->rpSkipTo == ST_FIRST_VARIABLE) + appendStringInfo(buf, "\n AFTER MATCH SKIP TO FIRST %s ", wc->rpSkipVariable); + else if (wc->rpSkipTo == ST_LAST_VARIABLE) + appendStringInfo(buf, "\n AFTER MATCH SKIP TO LAST %s ", wc->rpSkipVariable); + else if (wc->rpSkipTo == ST_VARIABLE) + appendStringInfo(buf, "\n AFTER MATCH SKIP TO %s ", wc->rpSkipVariable); + + if (wc->initial) + appendStringInfoString(buf, "\n INITIAL"); + + if (wc->patternVariable) + { + appendStringInfoString(buf, "\n PATTERN "); + get_rule_pattern(wc->patternVariable, wc->patternRegexp, false, context); + } + + if (wc->defineClause) + { + appendStringInfoString(buf, "\n DEFINE\n"); + get_rule_define(wc->defineClause, wc->patternVariable, false, context); + appendStringInfoChar(buf, ' '); + } + /* we will now have a trailing space; remove it */ buf->len--; } -- 2.25.1 ----Next_Part(Mon_Jan_22_19_26_18_2024_011)-- Content-Type: Text/X-Patch; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="v13-0004-Row-pattern-recognition-patch-planner.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --iWwo79nqhOvOs5kf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --AcCatzXgbvyipyEy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --IRGsBYp1UN8d6WrT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --3/nz5wg6+DYwHsLU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --zd8Z8rlPOcTi77n/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --eEEy3EHc57lA8spa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --m23X5uHFNxthGTU3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --GzYugJnip6WHHvTk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --iWwo79nqhOvOs5kf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --AcCatzXgbvyipyEy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --IRGsBYp1UN8d6WrT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --eEEy3EHc57lA8spa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --GzYugJnip6WHHvTk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --iWwo79nqhOvOs5kf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --AcCatzXgbvyipyEy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --IRGsBYp1UN8d6WrT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --3/nz5wg6+DYwHsLU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --zd8Z8rlPOcTi77n/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --eEEy3EHc57lA8spa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --m23X5uHFNxthGTU3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --GzYugJnip6WHHvTk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --iWwo79nqhOvOs5kf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --AcCatzXgbvyipyEy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --IRGsBYp1UN8d6WrT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --3/nz5wg6+DYwHsLU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --zd8Z8rlPOcTi77n/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --eEEy3EHc57lA8spa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --m23X5uHFNxthGTU3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --GzYugJnip6WHHvTk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --iWwo79nqhOvOs5kf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --AcCatzXgbvyipyEy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --IRGsBYp1UN8d6WrT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --3/nz5wg6+DYwHsLU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --zd8Z8rlPOcTi77n/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --eEEy3EHc57lA8spa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --m23X5uHFNxthGTU3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --GzYugJnip6WHHvTk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --iWwo79nqhOvOs5kf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --AcCatzXgbvyipyEy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --IRGsBYp1UN8d6WrT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --3/nz5wg6+DYwHsLU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --zd8Z8rlPOcTi77n/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --eEEy3EHc57lA8spa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --m23X5uHFNxthGTU3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --GzYugJnip6WHHvTk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --iWwo79nqhOvOs5kf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --AcCatzXgbvyipyEy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --IRGsBYp1UN8d6WrT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --zd8Z8rlPOcTi77n/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --eEEy3EHc57lA8spa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --m23X5uHFNxthGTU3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --GzYugJnip6WHHvTk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --iWwo79nqhOvOs5kf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --AcCatzXgbvyipyEy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --IRGsBYp1UN8d6WrT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --3/nz5wg6+DYwHsLU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --zd8Z8rlPOcTi77n/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --eEEy3EHc57lA8spa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --m23X5uHFNxthGTU3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --GzYugJnip6WHHvTk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --iWwo79nqhOvOs5kf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --AcCatzXgbvyipyEy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --IRGsBYp1UN8d6WrT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --3/nz5wg6+DYwHsLU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --zd8Z8rlPOcTi77n/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --eEEy3EHc57lA8spa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --m23X5uHFNxthGTU3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --GzYugJnip6WHHvTk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --iWwo79nqhOvOs5kf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --AcCatzXgbvyipyEy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --IRGsBYp1UN8d6WrT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --3/nz5wg6+DYwHsLU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --zd8Z8rlPOcTi77n/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --eEEy3EHc57lA8spa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --m23X5uHFNxthGTU3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --GzYugJnip6WHHvTk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --AcCatzXgbvyipyEy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --IRGsBYp1UN8d6WrT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --3/nz5wg6+DYwHsLU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --zd8Z8rlPOcTi77n/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --m23X5uHFNxthGTU3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --GzYugJnip6WHHvTk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --iWwo79nqhOvOs5kf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --IRGsBYp1UN8d6WrT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --3/nz5wg6+DYwHsLU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --zd8Z8rlPOcTi77n/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --m23X5uHFNxthGTU3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --GzYugJnip6WHHvTk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --iWwo79nqhOvOs5kf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --AcCatzXgbvyipyEy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --IRGsBYp1UN8d6WrT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --3/nz5wg6+DYwHsLU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --zd8Z8rlPOcTi77n/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --m23X5uHFNxthGTU3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --GzYugJnip6WHHvTk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --iWwo79nqhOvOs5kf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --AcCatzXgbvyipyEy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --IRGsBYp1UN8d6WrT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --3/nz5wg6+DYwHsLU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --zd8Z8rlPOcTi77n/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --eEEy3EHc57lA8spa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --m23X5uHFNxthGTU3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --GzYugJnip6WHHvTk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --iWwo79nqhOvOs5kf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --AcCatzXgbvyipyEy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --IRGsBYp1UN8d6WrT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --3/nz5wg6+DYwHsLU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --zd8Z8rlPOcTi77n/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --eEEy3EHc57lA8spa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --m23X5uHFNxthGTU3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --GzYugJnip6WHHvTk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --iWwo79nqhOvOs5kf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --AcCatzXgbvyipyEy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --IRGsBYp1UN8d6WrT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --3/nz5wg6+DYwHsLU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --eEEy3EHc57lA8spa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --m23X5uHFNxthGTU3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --GzYugJnip6WHHvTk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --iWwo79nqhOvOs5kf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --AcCatzXgbvyipyEy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --IRGsBYp1UN8d6WrT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --3/nz5wg6+DYwHsLU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --zd8Z8rlPOcTi77n/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --eEEy3EHc57lA8spa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --m23X5uHFNxthGTU3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --GzYugJnip6WHHvTk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --iWwo79nqhOvOs5kf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --AcCatzXgbvyipyEy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --IRGsBYp1UN8d6WrT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --IRGsBYp1UN8d6WrT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --3/nz5wg6+DYwHsLU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --zd8Z8rlPOcTi77n/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --eEEy3EHc57lA8spa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --m23X5uHFNxthGTU3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --GzYugJnip6WHHvTk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --iWwo79nqhOvOs5kf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --AcCatzXgbvyipyEy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --IRGsBYp1UN8d6WrT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --3/nz5wg6+DYwHsLU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --zd8Z8rlPOcTi77n/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --AcCatzXgbvyipyEy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --IRGsBYp1UN8d6WrT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --3/nz5wg6+DYwHsLU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --zd8Z8rlPOcTi77n/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --eEEy3EHc57lA8spa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --m23X5uHFNxthGTU3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --GzYugJnip6WHHvTk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --iWwo79nqhOvOs5kf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --AcCatzXgbvyipyEy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --IRGsBYp1UN8d6WrT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --3/nz5wg6+DYwHsLU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --zd8Z8rlPOcTi77n/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --eEEy3EHc57lA8spa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --m23X5uHFNxthGTU3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --GzYugJnip6WHHvTk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --iWwo79nqhOvOs5kf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --3/nz5wg6+DYwHsLU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --zd8Z8rlPOcTi77n/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --m23X5uHFNxthGTU3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --3/nz5wg6+DYwHsLU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --zd8Z8rlPOcTi77n/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --eEEy3EHc57lA8spa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --m23X5uHFNxthGTU3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --GzYugJnip6WHHvTk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --iWwo79nqhOvOs5kf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --AcCatzXgbvyipyEy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --IRGsBYp1UN8d6WrT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --3/nz5wg6+DYwHsLU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --zd8Z8rlPOcTi77n/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --eEEy3EHc57lA8spa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --GzYugJnip6WHHvTk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --iWwo79nqhOvOs5kf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --AcCatzXgbvyipyEy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --3/nz5wg6+DYwHsLU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --zd8Z8rlPOcTi77n/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --eEEy3EHc57lA8spa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --m23X5uHFNxthGTU3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --GzYugJnip6WHHvTk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --AcCatzXgbvyipyEy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --IRGsBYp1UN8d6WrT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --3/nz5wg6+DYwHsLU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --zd8Z8rlPOcTi77n/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --m23X5uHFNxthGTU3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --GzYugJnip6WHHvTk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --AcCatzXgbvyipyEy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --IRGsBYp1UN8d6WrT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --3/nz5wg6+DYwHsLU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --zd8Z8rlPOcTi77n/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --eEEy3EHc57lA8spa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --m23X5uHFNxthGTU3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --GzYugJnip6WHHvTk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --AcCatzXgbvyipyEy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --IRGsBYp1UN8d6WrT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --3/nz5wg6+DYwHsLU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --zd8Z8rlPOcTi77n/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --m23X5uHFNxthGTU3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --GzYugJnip6WHHvTk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --iWwo79nqhOvOs5kf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --AcCatzXgbvyipyEy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --IRGsBYp1UN8d6WrT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --3/nz5wg6+DYwHsLU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --zd8Z8rlPOcTi77n/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --m23X5uHFNxthGTU3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --GzYugJnip6WHHvTk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --iWwo79nqhOvOs5kf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --AcCatzXgbvyipyEy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --IRGsBYp1UN8d6WrT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --3/nz5wg6+DYwHsLU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --zd8Z8rlPOcTi77n/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --eEEy3EHc57lA8spa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --m23X5uHFNxthGTU3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --GzYugJnip6WHHvTk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --iWwo79nqhOvOs5kf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --AcCatzXgbvyipyEy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --3/nz5wg6+DYwHsLU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --IRGsBYp1UN8d6WrT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --3/nz5wg6+DYwHsLU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --zd8Z8rlPOcTi77n/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --eEEy3EHc57lA8spa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --m23X5uHFNxthGTU3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --GzYugJnip6WHHvTk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --iWwo79nqhOvOs5kf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --AcCatzXgbvyipyEy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --IRGsBYp1UN8d6WrT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --3/nz5wg6+DYwHsLU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --zd8Z8rlPOcTi77n/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --eEEy3EHc57lA8spa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --m23X5uHFNxthGTU3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --GzYugJnip6WHHvTk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --iWwo79nqhOvOs5kf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --AcCatzXgbvyipyEy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --IRGsBYp1UN8d6WrT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --3/nz5wg6+DYwHsLU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --zd8Z8rlPOcTi77n/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --eEEy3EHc57lA8spa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --m23X5uHFNxthGTU3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --GzYugJnip6WHHvTk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --iWwo79nqhOvOs5kf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --AcCatzXgbvyipyEy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --IRGsBYp1UN8d6WrT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --3/nz5wg6+DYwHsLU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --zd8Z8rlPOcTi77n/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --eEEy3EHc57lA8spa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --m23X5uHFNxthGTU3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --GzYugJnip6WHHvTk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --iWwo79nqhOvOs5kf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --AcCatzXgbvyipyEy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --IRGsBYp1UN8d6WrT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --zd8Z8rlPOcTi77n/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --eEEy3EHc57lA8spa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --GzYugJnip6WHHvTk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --iWwo79nqhOvOs5kf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --AcCatzXgbvyipyEy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --iWwo79nqhOvOs5kf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --IRGsBYp1UN8d6WrT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --3/nz5wg6+DYwHsLU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --zd8Z8rlPOcTi77n/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --eEEy3EHc57lA8spa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --m23X5uHFNxthGTU3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --GzYugJnip6WHHvTk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --iWwo79nqhOvOs5kf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --AcCatzXgbvyipyEy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --eEEy3EHc57lA8spa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --AcCatzXgbvyipyEy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --IRGsBYp1UN8d6WrT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --3/nz5wg6+DYwHsLU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --zd8Z8rlPOcTi77n/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --eEEy3EHc57lA8spa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --m23X5uHFNxthGTU3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --GzYugJnip6WHHvTk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --iWwo79nqhOvOs5kf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --AcCatzXgbvyipyEy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --IRGsBYp1UN8d6WrT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --3/nz5wg6+DYwHsLU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --zd8Z8rlPOcTi77n/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --eEEy3EHc57lA8spa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --iWwo79nqhOvOs5kf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --AcCatzXgbvyipyEy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --eEEy3EHc57lA8spa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --IRGsBYp1UN8d6WrT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --3/nz5wg6+DYwHsLU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --zd8Z8rlPOcTi77n/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --eEEy3EHc57lA8spa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --m23X5uHFNxthGTU3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --GzYugJnip6WHHvTk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --iWwo79nqhOvOs5kf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --AcCatzXgbvyipyEy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --3/nz5wg6+DYwHsLU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --zd8Z8rlPOcTi77n/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --m23X5uHFNxthGTU3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --GzYugJnip6WHHvTk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --iWwo79nqhOvOs5kf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --AcCatzXgbvyipyEy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --eEEy3EHc57lA8spa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --IRGsBYp1UN8d6WrT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --3/nz5wg6+DYwHsLU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --zd8Z8rlPOcTi77n/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --eEEy3EHc57lA8spa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --m23X5uHFNxthGTU3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --GzYugJnip6WHHvTk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --iWwo79nqhOvOs5kf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --AcCatzXgbvyipyEy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --zd8Z8rlPOcTi77n/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --m23X5uHFNxthGTU3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --GzYugJnip6WHHvTk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --eEEy3EHc57lA8spa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --iWwo79nqhOvOs5kf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --IRGsBYp1UN8d6WrT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --m23X5uHFNxthGTU3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --IRGsBYp1UN8d6WrT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --iWwo79nqhOvOs5kf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --eEEy3EHc57lA8spa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --iWwo79nqhOvOs5kf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --iWwo79nqhOvOs5kf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --eEEy3EHc57lA8spa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --eEEy3EHc57lA8spa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --IRGsBYp1UN8d6WrT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --3/nz5wg6+DYwHsLU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --m23X5uHFNxthGTU3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --m23X5uHFNxthGTU3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --GzYugJnip6WHHvTk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --eEEy3EHc57lA8spa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --eEEy3EHc57lA8spa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --m23X5uHFNxthGTU3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --GzYugJnip6WHHvTk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --3/nz5wg6+DYwHsLU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --zd8Z8rlPOcTi77n/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --iWwo79nqhOvOs5kf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --AcCatzXgbvyipyEy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --AcCatzXgbvyipyEy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --IRGsBYp1UN8d6WrT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --3/nz5wg6+DYwHsLU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --zd8Z8rlPOcTi77n/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --eEEy3EHc57lA8spa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch" ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --m23X5uHFNxthGTU3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql @ 2025-12-09 17:33 Mark Wong <[email protected]> 0 siblings, 0 replies; 342+ messages in thread From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw) 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 --GzYugJnip6WHHvTk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch ^ permalink raw reply [nested|flat] 342+ messages in thread
end of thread, other threads:[~2025-12-09 17:33 UTC | newest] Thread overview: 342+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2022-04-04 22:13 [PATCH v20220916 07/13] DISCARD VARIABLES command [email protected] <[email protected]> 2022-04-04 22:13 [PATCH v20220922 07/13] DISCARD VARIABLES command [email protected] <[email protected]> 2022-04-04 22:13 [PATCH 05/11] DISCARD VARIABLES command [email protected] <[email protected]> 2022-04-04 22:13 [PATCH v20220916 07/13] DISCARD VARIABLES command [email protected] <[email protected]> 2022-04-04 22:13 [PATCH 05/11] DISCARD VARIABLES command [email protected] <[email protected]> 2024-01-22 09:45 [PATCH v13 3/8] Row pattern recognition patch (rewriter). Tatsuo Ishii <[email protected]> 2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]> 2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
This inbox is served by agora; see mirroring instructions for how to clone and mirror all data and code used for this inbox