agora inbox for [email protected]help / color / mirror / Atom feed
[PATCH v20220916 07/13] DISCARD VARIABLES command 398+ 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; 398+ 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] 398+ messages in thread
* [PATCH 05/11] DISCARD VARIABLES command @ 2022-04-04 22:13 [email protected] <[email protected]> 0 siblings, 0 replies; 398+ 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] 398+ messages in thread
* [PATCH v20220916 07/13] DISCARD VARIABLES command @ 2022-04-04 22:13 [email protected] <[email protected]> 0 siblings, 0 replies; 398+ 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] 398+ messages in thread
* [PATCH v20220922 07/13] DISCARD VARIABLES command @ 2022-04-04 22:13 [email protected] <[email protected]> 0 siblings, 0 replies; 398+ 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] 398+ messages in thread
* [PATCH 05/11] DISCARD VARIABLES command @ 2022-04-04 22:13 [email protected] <[email protected]> 0 siblings, 0 replies; 398+ 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] 398+ messages in thread
* [PATCH v12 3/3] pg_test_timing: Add --fast flag to test fast timing, report time source @ 2025-07-27 15:48 Lukas Fittl <[email protected]> 0 siblings, 0 replies; 398+ messages in thread From: Lukas Fittl @ 2025-07-27 15:48 UTC (permalink / raw) In passing also reduce the per-loop overhead caused by repeated divisions in INSTR_TIME_GET_NANOSEC when the ticks variable has become very large, instead diff first and then turn it into nanosecs. --- src/bin/pg_test_timing/pg_test_timing.c | 59 +++++++++++++++++++------ src/include/portability/instr_time.h | 30 ++++++++----- 2 files changed, 65 insertions(+), 24 deletions(-) diff --git a/src/bin/pg_test_timing/pg_test_timing.c b/src/bin/pg_test_timing/pg_test_timing.c index a5621251afc..b77ef2063b6 100644 --- a/src/bin/pg_test_timing/pg_test_timing.c +++ b/src/bin/pg_test_timing/pg_test_timing.c @@ -16,6 +16,7 @@ static const char *progname; static unsigned int test_duration = 3; static double max_rprct = 99.99; +static bool fast_timing = false; /* record duration in powers of 2 nanoseconds */ static long long int histogram[32]; @@ -56,6 +57,7 @@ handle_args(int argc, char *argv[]) static struct option long_options[] = { {"duration", required_argument, NULL, 'd'}, {"cutoff", required_argument, NULL, 'c'}, + {"fast", no_argument, NULL, 'f'}, {NULL, 0, NULL, 0} }; @@ -68,7 +70,7 @@ handle_args(int argc, char *argv[]) { if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0) { - printf(_("Usage: %s [-d DURATION] [-c CUTOFF]\n"), progname); + printf(_("Usage: %s [-d DURATION] [-c CUTOFF] [--fast]\n"), progname); exit(0); } if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0) @@ -78,7 +80,7 @@ handle_args(int argc, char *argv[]) } } - while ((option = getopt_long(argc, argv, "d:c:", + while ((option = getopt_long(argc, argv, "d:c:f:", long_options, &optindex)) != -1) { switch (option) @@ -125,6 +127,10 @@ handle_args(int argc, char *argv[]) } break; + case 'f': + fast_timing = true; + break; + default: fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname); @@ -155,11 +161,31 @@ test_timing(unsigned int duration) uint64 total_time; int64 time_elapsed = 0; uint64 loop_count = 0; - uint64 prev, - cur; instr_time start_time, end_time, - temp; + prev, + cur; + char *time_source = NULL; + bool fast_timing_used = false; + + INSTR_TIME_INITIALIZE(); + +#if !defined(WIN32) && defined(__x86_64__) && defined(__linux__) + if (fast_timing && has_rdtsc) + { + time_source = "RDTSC"; + fast_timing_used = true; + } + else if (has_rdtscp) + time_source = "RDTSCP"; + else + time_source = PG_INSTR_CLOCK_NAME; +#else + time_source = PG_INSTR_CLOCK_NAME; +#endif + if (fast_timing && !fast_timing_used) + printf(_("Warning: Fast timing requested, but not available - regular timing source will be used\n")); + printf(_("Time source: %s\n"), time_source); /* * Pre-zero the statistics data structures. They're already zero by @@ -173,8 +199,11 @@ test_timing(unsigned int duration) total_time = duration > 0 ? duration * INT64CONST(1000000000) : 0; - INSTR_TIME_SET_CURRENT(start_time); - cur = INSTR_TIME_GET_NANOSEC(start_time); + if (fast_timing) + INSTR_TIME_SET_CURRENT_FAST(start_time); + else + INSTR_TIME_SET_CURRENT(start_time); + cur = start_time; while (time_elapsed < total_time) { @@ -182,9 +211,11 @@ test_timing(unsigned int duration) bits; prev = cur; - INSTR_TIME_SET_CURRENT(temp); - cur = INSTR_TIME_GET_NANOSEC(temp); - diff = cur - prev; + if (fast_timing) + INSTR_TIME_SET_CURRENT_FAST(cur); + else + INSTR_TIME_SET_CURRENT(cur); + diff = INSTR_TIME_DIFF_NANOSEC(cur, prev); /* Did time go backwards? */ if (unlikely(diff < 0)) @@ -217,11 +248,13 @@ test_timing(unsigned int duration) largest_diff_count++; loop_count++; - INSTR_TIME_SUBTRACT(temp, start_time); - time_elapsed = INSTR_TIME_GET_NANOSEC(temp); + time_elapsed = INSTR_TIME_DIFF_NANOSEC(cur, start_time); } - INSTR_TIME_SET_CURRENT(end_time); + if (fast_timing) + INSTR_TIME_SET_CURRENT_FAST(end_time); + else + INSTR_TIME_SET_CURRENT(end_time); INSTR_TIME_SUBTRACT(end_time, start_time); diff --git a/src/include/portability/instr_time.h b/src/include/portability/instr_time.h index e2e339a0c4f..f02296f1026 100644 --- a/src/include/portability/instr_time.h +++ b/src/include/portability/instr_time.h @@ -112,10 +112,13 @@ extern int64 max_ticks_no_overflow; */ #if defined(__darwin__) && defined(CLOCK_MONOTONIC_RAW) #define PG_INSTR_CLOCK CLOCK_MONOTONIC_RAW +#define PG_INSTR_CLOCK_NAME "clock_gettime (CLOCK_MONOTONIC_RAW)" #elif defined(CLOCK_MONOTONIC) #define PG_INSTR_CLOCK CLOCK_MONOTONIC +#define PG_INSTR_CLOCK_NAME "clock_gettime (CLOCK_MONOTONIC)" #else #define PG_INSTR_CLOCK CLOCK_REALTIME +#define PG_INSTR_CLOCK_NAME "clock_gettime (CLOCK_REALTIME)" #endif #if defined(__x86_64__) && defined(__linux__) @@ -174,7 +177,7 @@ pg_get_ticks(void) } static inline int64_t -pg_ticks_to_ns(instr_time t) +pg_ticks_to_ns(int64 ticks) { /* * Would multiplication overflow? If so perform computation in two parts. @@ -183,7 +186,7 @@ pg_ticks_to_ns(instr_time t) */ int64 ns = 0; - if (unlikely(t.ticks > max_ticks_no_overflow)) + if (unlikely(ticks > max_ticks_no_overflow)) { /* * Compute how often the maximum number of ticks fits completely into @@ -192,7 +195,7 @@ pg_ticks_to_ns(instr_time t) * value. In a 2nd step we adjust the number of elapsed ticks and * convert the remaining ticks. */ - int64 count = t.ticks / max_ticks_no_overflow; + int64 count = ticks / max_ticks_no_overflow; int64 max_ns = max_ticks_no_overflow * ticks_per_ns_scaled / TICKS_TO_NS_PRECISION; ns = max_ns * count; @@ -201,11 +204,11 @@ pg_ticks_to_ns(instr_time t) * Subtract the ticks that we now already accounted for, so that they * don't get counted twice. */ - t.ticks -= count * max_ticks_no_overflow; - Assert(t.ticks >= 0); + ticks -= count * max_ticks_no_overflow; + Assert(ticks >= 0); } - ns += t.ticks * ticks_per_ns_scaled / TICKS_TO_NS_PRECISION; + ns += ticks * ticks_per_ns_scaled / TICKS_TO_NS_PRECISION; return ns; } @@ -226,14 +229,14 @@ pg_initialize_get_ticks() #define INSTR_TIME_SET_CURRENT(t) \ ((t) = pg_get_ticks()) -#define INSTR_TIME_GET_NANOSEC(t) \ - pg_ticks_to_ns(t) - +#define INSTR_TIME_TICKS_TO_NANOSEC(ticks) \ + (pg_ticks_to_ns(ticks)) #else /* WIN32 */ /* Use QueryPerformanceCounter() */ +#define PG_INSTR_CLOCK_NAME "QueryPerformanceCounter" /* helper for INSTR_TIME_SET_CURRENT / INSTR_TIME_SET_CURRENT_FAST */ static inline instr_time @@ -265,8 +268,8 @@ GetTimerFrequency(void) #define INSTR_TIME_SET_CURRENT(t) \ ((t) = pg_query_performance_counter()) -#define INSTR_TIME_GET_NANOSEC(t) \ - ((int64) ((t).ticks * ((double) NS_PER_S / GetTimerFrequency()))) +#define INSTR_TIME_TICKS_TO_NANOSEC(ticks) \ + ((int64) ((ticks) * ((double) NS_PER_S / GetTimerFrequency()))) #endif /* WIN32 */ @@ -285,9 +288,14 @@ GetTimerFrequency(void) #define INSTR_TIME_SUBTRACT(x,y) \ ((x).ticks -= (y).ticks) +#define INSTR_TIME_DIFF_NANOSEC(x,y) \ + (INSTR_TIME_TICKS_TO_NANOSEC((x).ticks - (y).ticks)) + #define INSTR_TIME_ACCUM_DIFF(x,y,z) \ ((x).ticks += (y).ticks - (z).ticks) +#define INSTR_TIME_GET_NANOSEC(t) \ + (INSTR_TIME_TICKS_TO_NANOSEC((t).ticks)) #define INSTR_TIME_GET_DOUBLE(t) \ ((double) INSTR_TIME_GET_NANOSEC(t) / NS_PER_S) -- 2.47.3 --vtqqtrpooseurzip-- ^ permalink raw reply [nested|flat] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ 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; 398+ 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] 398+ messages in thread
end of thread, other threads:[~2025-12-09 17:33 UTC | newest] Thread overview: 398+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2022-04-04 22:13 [PATCH v20220922 07/13] 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]> 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]> 2025-07-27 15:48 [PATCH v12 3/3] pg_test_timing: Add --fast flag to test fast timing, report time source Lukas Fittl <[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 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 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 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 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 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 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.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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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.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 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 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 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 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 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 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.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 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.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 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 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 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 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 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 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 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 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.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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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.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 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 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 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 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 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 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.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 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 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 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.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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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.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 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 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.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 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 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 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 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 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 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 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 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 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 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 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.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 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 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 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 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 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 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 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 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 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.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 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 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 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 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 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 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 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 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 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 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