agora inbox for [email protected]
help / color / mirror / Atom feed[PATCH v20220922 07/13] DISCARD VARIABLES command
342+ messages / 3 participants
[nested] [flat]
* [PATCH v20220922 07/13] DISCARD VARIABLES command
@ 2022-04-04 22:13 [email protected] <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: [email protected] @ 2022-04-04 22:13 UTC (permalink / raw)
---
src/backend/commands/discard.c | 6 ++++++
src/backend/parser/gram.y | 7 ++++++-
src/backend/tcop/utility.c | 3 +++
src/include/nodes/parsenodes.h | 3 ++-
src/include/tcop/cmdtaglist.h | 1 +
5 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/src/backend/commands/discard.c b/src/backend/commands/discard.c
index c583539e0c..68fe550a71 100644
--- a/src/backend/commands/discard.c
+++ b/src/backend/commands/discard.c
@@ -19,6 +19,7 @@
#include "commands/discard.h"
#include "commands/prepare.h"
#include "commands/sequence.h"
+#include "commands/session_variable.h"
#include "utils/guc.h"
#include "utils/portal.h"
@@ -48,6 +49,10 @@ DiscardCommand(DiscardStmt *stmt, bool isTopLevel)
ResetTempTableNamespace();
break;
+ case DISCARD_VARIABLES:
+ ResetSessionVariables();
+ break;
+
default:
elog(ERROR, "unrecognized DISCARD target: %d", stmt->target);
}
@@ -75,4 +80,5 @@ DiscardAll(bool isTopLevel)
ResetPlanCache();
ResetTempTableNamespace();
ResetSequenceCaches();
+ ResetSessionVariables();
}
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 9a45d94d9b..c1da4fb364 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -2024,7 +2024,12 @@ DiscardStmt:
n->target = DISCARD_SEQUENCES;
$$ = (Node *) n;
}
-
+ | DISCARD VARIABLES
+ {
+ DiscardStmt *n = makeNode(DiscardStmt);
+ n->target = DISCARD_VARIABLES;
+ $$ = (Node *) n;
+ }
;
diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c
index d267cea0e1..8fbccd1db6 100644
--- a/src/backend/tcop/utility.c
+++ b/src/backend/tcop/utility.c
@@ -2952,6 +2952,9 @@ CreateCommandTag(Node *parsetree)
case DISCARD_SEQUENCES:
tag = CMDTAG_DISCARD_SEQUENCES;
break;
+ case DISCARD_VARIABLES:
+ tag = CMDTAG_DISCARD_VARIABLES;
+ break;
default:
tag = CMDTAG_UNKNOWN;
}
diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h
index 323354ea16..6d0bf1eba5 100644
--- a/src/include/nodes/parsenodes.h
+++ b/src/include/nodes/parsenodes.h
@@ -3568,7 +3568,8 @@ typedef enum DiscardMode
DISCARD_ALL,
DISCARD_PLANS,
DISCARD_SEQUENCES,
- DISCARD_TEMP
+ DISCARD_TEMP,
+ DISCARD_VARIABLES
} DiscardMode;
typedef struct DiscardStmt
diff --git a/src/include/tcop/cmdtaglist.h b/src/include/tcop/cmdtaglist.h
index 357989b52f..09bd4d467f 100644
--- a/src/include/tcop/cmdtaglist.h
+++ b/src/include/tcop/cmdtaglist.h
@@ -135,6 +135,7 @@ PG_CMDTAG(CMDTAG_DISCARD_ALL, "DISCARD ALL", false, false, false)
PG_CMDTAG(CMDTAG_DISCARD_PLANS, "DISCARD PLANS", false, false, false)
PG_CMDTAG(CMDTAG_DISCARD_SEQUENCES, "DISCARD SEQUENCES", false, false, false)
PG_CMDTAG(CMDTAG_DISCARD_TEMP, "DISCARD TEMP", false, false, false)
+PG_CMDTAG(CMDTAG_DISCARD_VARIABLES, "DISCARD VARIABLES", false, false, false)
PG_CMDTAG(CMDTAG_DO, "DO", false, false, false)
PG_CMDTAG(CMDTAG_DROP_ACCESS_METHOD, "DROP ACCESS METHOD", true, false, false)
PG_CMDTAG(CMDTAG_DROP_AGGREGATE, "DROP AGGREGATE", true, false, false)
--
2.37.0
--z3ntqfnlkpftg4xg
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v20220922-0008-enhancing-psql-for-session-variables.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH 05/11] DISCARD VARIABLES command
@ 2022-04-04 22:13 [email protected] <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: [email protected] @ 2022-04-04 22:13 UTC (permalink / raw)
---
src/backend/commands/discard.c | 6 ++++++
src/backend/parser/gram.y | 7 ++++++-
src/backend/tcop/utility.c | 3 +++
src/include/nodes/parsenodes.h | 3 ++-
src/include/tcop/cmdtaglist.h | 1 +
5 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/src/backend/commands/discard.c b/src/backend/commands/discard.c
index c583539e0c..68fe550a71 100644
--- a/src/backend/commands/discard.c
+++ b/src/backend/commands/discard.c
@@ -19,6 +19,7 @@
#include "commands/discard.h"
#include "commands/prepare.h"
#include "commands/sequence.h"
+#include "commands/session_variable.h"
#include "utils/guc.h"
#include "utils/portal.h"
@@ -48,6 +49,10 @@ DiscardCommand(DiscardStmt *stmt, bool isTopLevel)
ResetTempTableNamespace();
break;
+ case DISCARD_VARIABLES:
+ ResetSessionVariables();
+ break;
+
default:
elog(ERROR, "unrecognized DISCARD target: %d", stmt->target);
}
@@ -75,4 +80,5 @@ DiscardAll(bool isTopLevel)
ResetPlanCache();
ResetTempTableNamespace();
ResetSequenceCaches();
+ ResetSessionVariables();
}
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 2b57daa264..745f2cbbf6 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -2027,7 +2027,12 @@ DiscardStmt:
n->target = DISCARD_SEQUENCES;
$$ = (Node *) n;
}
-
+ | DISCARD VARIABLES
+ {
+ DiscardStmt *n = makeNode(DiscardStmt);
+ n->target = DISCARD_VARIABLES;
+ $$ = (Node *) n;
+ }
;
diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c
index 724b74acb5..6c81f12dc7 100644
--- a/src/backend/tcop/utility.c
+++ b/src/backend/tcop/utility.c
@@ -2952,6 +2952,9 @@ CreateCommandTag(Node *parsetree)
case DISCARD_SEQUENCES:
tag = CMDTAG_DISCARD_SEQUENCES;
break;
+ case DISCARD_VARIABLES:
+ tag = CMDTAG_DISCARD_VARIABLES;
+ break;
default:
tag = CMDTAG_UNKNOWN;
}
diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h
index 52b2a037f6..c421b92816 100644
--- a/src/include/nodes/parsenodes.h
+++ b/src/include/nodes/parsenodes.h
@@ -3568,7 +3568,8 @@ typedef enum DiscardMode
DISCARD_ALL,
DISCARD_PLANS,
DISCARD_SEQUENCES,
- DISCARD_TEMP
+ DISCARD_TEMP,
+ DISCARD_VARIABLES
} DiscardMode;
typedef struct DiscardStmt
diff --git a/src/include/tcop/cmdtaglist.h b/src/include/tcop/cmdtaglist.h
index 357989b52f..09bd4d467f 100644
--- a/src/include/tcop/cmdtaglist.h
+++ b/src/include/tcop/cmdtaglist.h
@@ -135,6 +135,7 @@ PG_CMDTAG(CMDTAG_DISCARD_ALL, "DISCARD ALL", false, false, false)
PG_CMDTAG(CMDTAG_DISCARD_PLANS, "DISCARD PLANS", false, false, false)
PG_CMDTAG(CMDTAG_DISCARD_SEQUENCES, "DISCARD SEQUENCES", false, false, false)
PG_CMDTAG(CMDTAG_DISCARD_TEMP, "DISCARD TEMP", false, false, false)
+PG_CMDTAG(CMDTAG_DISCARD_VARIABLES, "DISCARD VARIABLES", false, false, false)
PG_CMDTAG(CMDTAG_DO, "DO", false, false, false)
PG_CMDTAG(CMDTAG_DROP_ACCESS_METHOD, "DROP ACCESS METHOD", true, false, false)
PG_CMDTAG(CMDTAG_DROP_AGGREGATE, "DROP AGGREGATE", true, false, false)
--
2.37.2
--gcms4zhgklsgym3k
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v20220906-1-0006-enhancing-psql-for-session-variables.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v20220916 07/13] DISCARD VARIABLES command
@ 2022-04-04 22:13 [email protected] <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: [email protected] @ 2022-04-04 22:13 UTC (permalink / raw)
---
src/backend/commands/discard.c | 6 ++++++
src/backend/parser/gram.y | 7 ++++++-
src/backend/tcop/utility.c | 3 +++
src/include/nodes/parsenodes.h | 3 ++-
src/include/tcop/cmdtaglist.h | 1 +
5 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/src/backend/commands/discard.c b/src/backend/commands/discard.c
index c583539e0c..68fe550a71 100644
--- a/src/backend/commands/discard.c
+++ b/src/backend/commands/discard.c
@@ -19,6 +19,7 @@
#include "commands/discard.h"
#include "commands/prepare.h"
#include "commands/sequence.h"
+#include "commands/session_variable.h"
#include "utils/guc.h"
#include "utils/portal.h"
@@ -48,6 +49,10 @@ DiscardCommand(DiscardStmt *stmt, bool isTopLevel)
ResetTempTableNamespace();
break;
+ case DISCARD_VARIABLES:
+ ResetSessionVariables();
+ break;
+
default:
elog(ERROR, "unrecognized DISCARD target: %d", stmt->target);
}
@@ -75,4 +80,5 @@ DiscardAll(bool isTopLevel)
ResetPlanCache();
ResetTempTableNamespace();
ResetSequenceCaches();
+ ResetSessionVariables();
}
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 1059a5c865..542be13a40 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -2024,7 +2024,12 @@ DiscardStmt:
n->target = DISCARD_SEQUENCES;
$$ = (Node *) n;
}
-
+ | DISCARD VARIABLES
+ {
+ DiscardStmt *n = makeNode(DiscardStmt);
+ n->target = DISCARD_VARIABLES;
+ $$ = (Node *) n;
+ }
;
diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c
index d267cea0e1..8fbccd1db6 100644
--- a/src/backend/tcop/utility.c
+++ b/src/backend/tcop/utility.c
@@ -2952,6 +2952,9 @@ CreateCommandTag(Node *parsetree)
case DISCARD_SEQUENCES:
tag = CMDTAG_DISCARD_SEQUENCES;
break;
+ case DISCARD_VARIABLES:
+ tag = CMDTAG_DISCARD_VARIABLES;
+ break;
default:
tag = CMDTAG_UNKNOWN;
}
diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h
index 323354ea16..6d0bf1eba5 100644
--- a/src/include/nodes/parsenodes.h
+++ b/src/include/nodes/parsenodes.h
@@ -3568,7 +3568,8 @@ typedef enum DiscardMode
DISCARD_ALL,
DISCARD_PLANS,
DISCARD_SEQUENCES,
- DISCARD_TEMP
+ DISCARD_TEMP,
+ DISCARD_VARIABLES
} DiscardMode;
typedef struct DiscardStmt
diff --git a/src/include/tcop/cmdtaglist.h b/src/include/tcop/cmdtaglist.h
index 357989b52f..09bd4d467f 100644
--- a/src/include/tcop/cmdtaglist.h
+++ b/src/include/tcop/cmdtaglist.h
@@ -135,6 +135,7 @@ PG_CMDTAG(CMDTAG_DISCARD_ALL, "DISCARD ALL", false, false, false)
PG_CMDTAG(CMDTAG_DISCARD_PLANS, "DISCARD PLANS", false, false, false)
PG_CMDTAG(CMDTAG_DISCARD_SEQUENCES, "DISCARD SEQUENCES", false, false, false)
PG_CMDTAG(CMDTAG_DISCARD_TEMP, "DISCARD TEMP", false, false, false)
+PG_CMDTAG(CMDTAG_DISCARD_VARIABLES, "DISCARD VARIABLES", false, false, false)
PG_CMDTAG(CMDTAG_DO, "DO", false, false, false)
PG_CMDTAG(CMDTAG_DROP_ACCESS_METHOD, "DROP ACCESS METHOD", true, false, false)
PG_CMDTAG(CMDTAG_DROP_AGGREGATE, "DROP AGGREGATE", true, false, false)
--
2.37.0
--w2in66fnadvggvsb
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v20220916-0008-enhancing-psql-for-session-variables.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH 05/11] DISCARD VARIABLES command
@ 2022-04-04 22:13 [email protected] <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: [email protected] @ 2022-04-04 22:13 UTC (permalink / raw)
---
src/backend/commands/discard.c | 6 ++++++
src/backend/parser/gram.y | 7 ++++++-
src/backend/tcop/utility.c | 3 +++
src/include/nodes/parsenodes.h | 3 ++-
src/include/tcop/cmdtaglist.h | 1 +
5 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/src/backend/commands/discard.c b/src/backend/commands/discard.c
index c583539e0c..68fe550a71 100644
--- a/src/backend/commands/discard.c
+++ b/src/backend/commands/discard.c
@@ -19,6 +19,7 @@
#include "commands/discard.h"
#include "commands/prepare.h"
#include "commands/sequence.h"
+#include "commands/session_variable.h"
#include "utils/guc.h"
#include "utils/portal.h"
@@ -48,6 +49,10 @@ DiscardCommand(DiscardStmt *stmt, bool isTopLevel)
ResetTempTableNamespace();
break;
+ case DISCARD_VARIABLES:
+ ResetSessionVariables();
+ break;
+
default:
elog(ERROR, "unrecognized DISCARD target: %d", stmt->target);
}
@@ -75,4 +80,5 @@ DiscardAll(bool isTopLevel)
ResetPlanCache();
ResetTempTableNamespace();
ResetSequenceCaches();
+ ResetSessionVariables();
}
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 2b57daa264..745f2cbbf6 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -2027,7 +2027,12 @@ DiscardStmt:
n->target = DISCARD_SEQUENCES;
$$ = (Node *) n;
}
-
+ | DISCARD VARIABLES
+ {
+ DiscardStmt *n = makeNode(DiscardStmt);
+ n->target = DISCARD_VARIABLES;
+ $$ = (Node *) n;
+ }
;
diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c
index 724b74acb5..6c81f12dc7 100644
--- a/src/backend/tcop/utility.c
+++ b/src/backend/tcop/utility.c
@@ -2952,6 +2952,9 @@ CreateCommandTag(Node *parsetree)
case DISCARD_SEQUENCES:
tag = CMDTAG_DISCARD_SEQUENCES;
break;
+ case DISCARD_VARIABLES:
+ tag = CMDTAG_DISCARD_VARIABLES;
+ break;
default:
tag = CMDTAG_UNKNOWN;
}
diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h
index 52b2a037f6..c421b92816 100644
--- a/src/include/nodes/parsenodes.h
+++ b/src/include/nodes/parsenodes.h
@@ -3568,7 +3568,8 @@ typedef enum DiscardMode
DISCARD_ALL,
DISCARD_PLANS,
DISCARD_SEQUENCES,
- DISCARD_TEMP
+ DISCARD_TEMP,
+ DISCARD_VARIABLES
} DiscardMode;
typedef struct DiscardStmt
diff --git a/src/include/tcop/cmdtaglist.h b/src/include/tcop/cmdtaglist.h
index 357989b52f..09bd4d467f 100644
--- a/src/include/tcop/cmdtaglist.h
+++ b/src/include/tcop/cmdtaglist.h
@@ -135,6 +135,7 @@ PG_CMDTAG(CMDTAG_DISCARD_ALL, "DISCARD ALL", false, false, false)
PG_CMDTAG(CMDTAG_DISCARD_PLANS, "DISCARD PLANS", false, false, false)
PG_CMDTAG(CMDTAG_DISCARD_SEQUENCES, "DISCARD SEQUENCES", false, false, false)
PG_CMDTAG(CMDTAG_DISCARD_TEMP, "DISCARD TEMP", false, false, false)
+PG_CMDTAG(CMDTAG_DISCARD_VARIABLES, "DISCARD VARIABLES", false, false, false)
PG_CMDTAG(CMDTAG_DO, "DO", false, false, false)
PG_CMDTAG(CMDTAG_DROP_ACCESS_METHOD, "DROP ACCESS METHOD", true, false, false)
PG_CMDTAG(CMDTAG_DROP_AGGREGATE, "DROP AGGREGATE", true, false, false)
--
2.37.2
--gcms4zhgklsgym3k
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v20220906-1-0006-enhancing-psql-for-session-variables.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v20220916 07/13] DISCARD VARIABLES command
@ 2022-04-04 22:13 [email protected] <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: [email protected] @ 2022-04-04 22:13 UTC (permalink / raw)
---
src/backend/commands/discard.c | 6 ++++++
src/backend/parser/gram.y | 7 ++++++-
src/backend/tcop/utility.c | 3 +++
src/include/nodes/parsenodes.h | 3 ++-
src/include/tcop/cmdtaglist.h | 1 +
5 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/src/backend/commands/discard.c b/src/backend/commands/discard.c
index c583539e0c..68fe550a71 100644
--- a/src/backend/commands/discard.c
+++ b/src/backend/commands/discard.c
@@ -19,6 +19,7 @@
#include "commands/discard.h"
#include "commands/prepare.h"
#include "commands/sequence.h"
+#include "commands/session_variable.h"
#include "utils/guc.h"
#include "utils/portal.h"
@@ -48,6 +49,10 @@ DiscardCommand(DiscardStmt *stmt, bool isTopLevel)
ResetTempTableNamespace();
break;
+ case DISCARD_VARIABLES:
+ ResetSessionVariables();
+ break;
+
default:
elog(ERROR, "unrecognized DISCARD target: %d", stmt->target);
}
@@ -75,4 +80,5 @@ DiscardAll(bool isTopLevel)
ResetPlanCache();
ResetTempTableNamespace();
ResetSequenceCaches();
+ ResetSessionVariables();
}
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 1059a5c865..542be13a40 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -2024,7 +2024,12 @@ DiscardStmt:
n->target = DISCARD_SEQUENCES;
$$ = (Node *) n;
}
-
+ | DISCARD VARIABLES
+ {
+ DiscardStmt *n = makeNode(DiscardStmt);
+ n->target = DISCARD_VARIABLES;
+ $$ = (Node *) n;
+ }
;
diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c
index d267cea0e1..8fbccd1db6 100644
--- a/src/backend/tcop/utility.c
+++ b/src/backend/tcop/utility.c
@@ -2952,6 +2952,9 @@ CreateCommandTag(Node *parsetree)
case DISCARD_SEQUENCES:
tag = CMDTAG_DISCARD_SEQUENCES;
break;
+ case DISCARD_VARIABLES:
+ tag = CMDTAG_DISCARD_VARIABLES;
+ break;
default:
tag = CMDTAG_UNKNOWN;
}
diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h
index 323354ea16..6d0bf1eba5 100644
--- a/src/include/nodes/parsenodes.h
+++ b/src/include/nodes/parsenodes.h
@@ -3568,7 +3568,8 @@ typedef enum DiscardMode
DISCARD_ALL,
DISCARD_PLANS,
DISCARD_SEQUENCES,
- DISCARD_TEMP
+ DISCARD_TEMP,
+ DISCARD_VARIABLES
} DiscardMode;
typedef struct DiscardStmt
diff --git a/src/include/tcop/cmdtaglist.h b/src/include/tcop/cmdtaglist.h
index 357989b52f..09bd4d467f 100644
--- a/src/include/tcop/cmdtaglist.h
+++ b/src/include/tcop/cmdtaglist.h
@@ -135,6 +135,7 @@ PG_CMDTAG(CMDTAG_DISCARD_ALL, "DISCARD ALL", false, false, false)
PG_CMDTAG(CMDTAG_DISCARD_PLANS, "DISCARD PLANS", false, false, false)
PG_CMDTAG(CMDTAG_DISCARD_SEQUENCES, "DISCARD SEQUENCES", false, false, false)
PG_CMDTAG(CMDTAG_DISCARD_TEMP, "DISCARD TEMP", false, false, false)
+PG_CMDTAG(CMDTAG_DISCARD_VARIABLES, "DISCARD VARIABLES", false, false, false)
PG_CMDTAG(CMDTAG_DO, "DO", false, false, false)
PG_CMDTAG(CMDTAG_DROP_ACCESS_METHOD, "DROP ACCESS METHOD", true, false, false)
PG_CMDTAG(CMDTAG_DROP_AGGREGATE, "DROP AGGREGATE", true, false, false)
--
2.37.0
--w2in66fnadvggvsb
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v20220916-0008-enhancing-psql-for-session-variables.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 954f611de5b..8d81dcdc2f6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8593,15 +8586,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--GzYugJnip6WHHvTk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 45e4483692d..5b22fdc8e08 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--iWwo79nqhOvOs5kf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 49e92204bd6..b00ede45e41 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--AcCatzXgbvyipyEy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index febed53c9fa..c7adfad0e05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index de063d63b4f..7d576834d5c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index c215d47f2d8..2d1aa50dac6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,13 +3952,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8494,12 +8487,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.51.2
--IRGsBYp1UN8d6WrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c4d424ba10d..57b4adc0e2a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 597c468983e..9b87b9eda5f 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--3/nz5wg6+DYwHsLU
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
src/include/catalog/pg_retired.dat | 4 ++-
4 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 3733212fe0a..29557f3c9d2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 2a3362567a7..531d0dea7db 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index a3ce10c7f62..d5d51ddb3e8 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,6 +17,8 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
-{ oid => '1573', proname => 'pg_get_ruledef' }
+{ oid => '1573', proname => 'pg_get_ruledef' },
+{ oid => '1640', proname => 'pg_get_viewdef' },
+{ oid => '1641', proname => 'pg_get_viewdef' }
]
--
2.43.0
--zd8Z8rlPOcTi77n/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 31e773fb32e..328f994547e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -659,25 +659,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -717,31 +698,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index b935b6f14c0..166ae4b5645 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3962,13 +3962,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8519,12 +8512,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--eEEy3EHc57lA8spa
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 99ece0c1761..24c59510672 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 66cb016792c..c1b945cdae5 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8583,12 +8576,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--m23X5uHFNxthGTU3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 954f611de5b..8d81dcdc2f6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8593,15 +8586,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--GzYugJnip6WHHvTk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 45e4483692d..5b22fdc8e08 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--iWwo79nqhOvOs5kf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 49e92204bd6..b00ede45e41 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--AcCatzXgbvyipyEy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index febed53c9fa..c7adfad0e05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index de063d63b4f..7d576834d5c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index c215d47f2d8..2d1aa50dac6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,13 +3952,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8494,12 +8487,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.51.2
--IRGsBYp1UN8d6WrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 31e773fb32e..328f994547e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -659,25 +659,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -717,31 +698,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index b935b6f14c0..166ae4b5645 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3962,13 +3962,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8519,12 +8512,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--eEEy3EHc57lA8spa
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 954f611de5b..8d81dcdc2f6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8593,15 +8586,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--GzYugJnip6WHHvTk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 45e4483692d..5b22fdc8e08 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--iWwo79nqhOvOs5kf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 49e92204bd6..b00ede45e41 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--AcCatzXgbvyipyEy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index febed53c9fa..c7adfad0e05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index de063d63b4f..7d576834d5c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index c215d47f2d8..2d1aa50dac6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,13 +3952,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8494,12 +8487,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.51.2
--IRGsBYp1UN8d6WrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c4d424ba10d..57b4adc0e2a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 597c468983e..9b87b9eda5f 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--3/nz5wg6+DYwHsLU
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
src/include/catalog/pg_retired.dat | 4 ++-
4 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 3733212fe0a..29557f3c9d2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 2a3362567a7..531d0dea7db 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index a3ce10c7f62..d5d51ddb3e8 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,6 +17,8 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
-{ oid => '1573', proname => 'pg_get_ruledef' }
+{ oid => '1573', proname => 'pg_get_ruledef' },
+{ oid => '1640', proname => 'pg_get_viewdef' },
+{ oid => '1641', proname => 'pg_get_viewdef' }
]
--
2.43.0
--zd8Z8rlPOcTi77n/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 31e773fb32e..328f994547e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -659,25 +659,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -717,31 +698,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index b935b6f14c0..166ae4b5645 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3962,13 +3962,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8519,12 +8512,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--eEEy3EHc57lA8spa
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 99ece0c1761..24c59510672 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 66cb016792c..c1b945cdae5 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8583,12 +8576,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--m23X5uHFNxthGTU3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 954f611de5b..8d81dcdc2f6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8593,15 +8586,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--GzYugJnip6WHHvTk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 45e4483692d..5b22fdc8e08 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--iWwo79nqhOvOs5kf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 49e92204bd6..b00ede45e41 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--AcCatzXgbvyipyEy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index febed53c9fa..c7adfad0e05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index de063d63b4f..7d576834d5c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index c215d47f2d8..2d1aa50dac6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,13 +3952,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8494,12 +8487,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.51.2
--IRGsBYp1UN8d6WrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c4d424ba10d..57b4adc0e2a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 597c468983e..9b87b9eda5f 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--3/nz5wg6+DYwHsLU
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
src/include/catalog/pg_retired.dat | 4 ++-
4 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 3733212fe0a..29557f3c9d2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 2a3362567a7..531d0dea7db 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index a3ce10c7f62..d5d51ddb3e8 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,6 +17,8 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
-{ oid => '1573', proname => 'pg_get_ruledef' }
+{ oid => '1573', proname => 'pg_get_ruledef' },
+{ oid => '1640', proname => 'pg_get_viewdef' },
+{ oid => '1641', proname => 'pg_get_viewdef' }
]
--
2.43.0
--zd8Z8rlPOcTi77n/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 31e773fb32e..328f994547e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -659,25 +659,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -717,31 +698,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index b935b6f14c0..166ae4b5645 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3962,13 +3962,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8519,12 +8512,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--eEEy3EHc57lA8spa
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 99ece0c1761..24c59510672 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 66cb016792c..c1b945cdae5 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8583,12 +8576,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--m23X5uHFNxthGTU3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 954f611de5b..8d81dcdc2f6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8593,15 +8586,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--GzYugJnip6WHHvTk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 45e4483692d..5b22fdc8e08 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--iWwo79nqhOvOs5kf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 49e92204bd6..b00ede45e41 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--AcCatzXgbvyipyEy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index febed53c9fa..c7adfad0e05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index de063d63b4f..7d576834d5c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index c215d47f2d8..2d1aa50dac6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,13 +3952,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8494,12 +8487,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.51.2
--IRGsBYp1UN8d6WrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c4d424ba10d..57b4adc0e2a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 597c468983e..9b87b9eda5f 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--3/nz5wg6+DYwHsLU
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
src/include/catalog/pg_retired.dat | 4 ++-
4 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 3733212fe0a..29557f3c9d2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 2a3362567a7..531d0dea7db 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index a3ce10c7f62..d5d51ddb3e8 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,6 +17,8 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
-{ oid => '1573', proname => 'pg_get_ruledef' }
+{ oid => '1573', proname => 'pg_get_ruledef' },
+{ oid => '1640', proname => 'pg_get_viewdef' },
+{ oid => '1641', proname => 'pg_get_viewdef' }
]
--
2.43.0
--zd8Z8rlPOcTi77n/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 31e773fb32e..328f994547e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -659,25 +659,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -717,31 +698,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index b935b6f14c0..166ae4b5645 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3962,13 +3962,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8519,12 +8512,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--eEEy3EHc57lA8spa
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 99ece0c1761..24c59510672 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 66cb016792c..c1b945cdae5 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8583,12 +8576,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--m23X5uHFNxthGTU3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 954f611de5b..8d81dcdc2f6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8593,15 +8586,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--GzYugJnip6WHHvTk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 45e4483692d..5b22fdc8e08 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--iWwo79nqhOvOs5kf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 49e92204bd6..b00ede45e41 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--AcCatzXgbvyipyEy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index febed53c9fa..c7adfad0e05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index de063d63b4f..7d576834d5c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index c215d47f2d8..2d1aa50dac6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,13 +3952,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8494,12 +8487,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.51.2
--IRGsBYp1UN8d6WrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c4d424ba10d..57b4adc0e2a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 597c468983e..9b87b9eda5f 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--3/nz5wg6+DYwHsLU
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
src/include/catalog/pg_retired.dat | 4 ++-
4 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 3733212fe0a..29557f3c9d2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 2a3362567a7..531d0dea7db 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index a3ce10c7f62..d5d51ddb3e8 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,6 +17,8 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
-{ oid => '1573', proname => 'pg_get_ruledef' }
+{ oid => '1573', proname => 'pg_get_ruledef' },
+{ oid => '1640', proname => 'pg_get_viewdef' },
+{ oid => '1641', proname => 'pg_get_viewdef' }
]
--
2.43.0
--zd8Z8rlPOcTi77n/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 31e773fb32e..328f994547e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -659,25 +659,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -717,31 +698,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index b935b6f14c0..166ae4b5645 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3962,13 +3962,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8519,12 +8512,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--eEEy3EHc57lA8spa
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 99ece0c1761..24c59510672 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 66cb016792c..c1b945cdae5 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8583,12 +8576,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--m23X5uHFNxthGTU3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 954f611de5b..8d81dcdc2f6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8593,15 +8586,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--GzYugJnip6WHHvTk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 45e4483692d..5b22fdc8e08 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--iWwo79nqhOvOs5kf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 49e92204bd6..b00ede45e41 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--AcCatzXgbvyipyEy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index febed53c9fa..c7adfad0e05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index de063d63b4f..7d576834d5c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index c215d47f2d8..2d1aa50dac6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,13 +3952,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8494,12 +8487,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.51.2
--IRGsBYp1UN8d6WrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
src/include/catalog/pg_retired.dat | 4 ++-
4 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 3733212fe0a..29557f3c9d2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 2a3362567a7..531d0dea7db 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index a3ce10c7f62..d5d51ddb3e8 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,6 +17,8 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
-{ oid => '1573', proname => 'pg_get_ruledef' }
+{ oid => '1573', proname => 'pg_get_ruledef' },
+{ oid => '1640', proname => 'pg_get_viewdef' },
+{ oid => '1641', proname => 'pg_get_viewdef' }
]
--
2.43.0
--zd8Z8rlPOcTi77n/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 31e773fb32e..328f994547e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -659,25 +659,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -717,31 +698,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index b935b6f14c0..166ae4b5645 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3962,13 +3962,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8519,12 +8512,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--eEEy3EHc57lA8spa
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 99ece0c1761..24c59510672 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 66cb016792c..c1b945cdae5 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8583,12 +8576,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--m23X5uHFNxthGTU3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 954f611de5b..8d81dcdc2f6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8593,15 +8586,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--GzYugJnip6WHHvTk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 45e4483692d..5b22fdc8e08 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--iWwo79nqhOvOs5kf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 49e92204bd6..b00ede45e41 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--AcCatzXgbvyipyEy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index febed53c9fa..c7adfad0e05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index de063d63b4f..7d576834d5c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index c215d47f2d8..2d1aa50dac6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,13 +3952,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8494,12 +8487,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.51.2
--IRGsBYp1UN8d6WrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c4d424ba10d..57b4adc0e2a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 597c468983e..9b87b9eda5f 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--3/nz5wg6+DYwHsLU
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
src/include/catalog/pg_retired.dat | 4 ++-
4 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 3733212fe0a..29557f3c9d2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 2a3362567a7..531d0dea7db 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index a3ce10c7f62..d5d51ddb3e8 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,6 +17,8 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
-{ oid => '1573', proname => 'pg_get_ruledef' }
+{ oid => '1573', proname => 'pg_get_ruledef' },
+{ oid => '1640', proname => 'pg_get_viewdef' },
+{ oid => '1641', proname => 'pg_get_viewdef' }
]
--
2.43.0
--zd8Z8rlPOcTi77n/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 31e773fb32e..328f994547e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -659,25 +659,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -717,31 +698,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index b935b6f14c0..166ae4b5645 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3962,13 +3962,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8519,12 +8512,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--eEEy3EHc57lA8spa
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 99ece0c1761..24c59510672 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 66cb016792c..c1b945cdae5 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8583,12 +8576,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--m23X5uHFNxthGTU3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 954f611de5b..8d81dcdc2f6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8593,15 +8586,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--GzYugJnip6WHHvTk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 45e4483692d..5b22fdc8e08 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--iWwo79nqhOvOs5kf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 49e92204bd6..b00ede45e41 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--AcCatzXgbvyipyEy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index febed53c9fa..c7adfad0e05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index de063d63b4f..7d576834d5c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index c215d47f2d8..2d1aa50dac6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,13 +3952,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8494,12 +8487,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.51.2
--IRGsBYp1UN8d6WrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c4d424ba10d..57b4adc0e2a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 597c468983e..9b87b9eda5f 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--3/nz5wg6+DYwHsLU
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
src/include/catalog/pg_retired.dat | 4 ++-
4 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 3733212fe0a..29557f3c9d2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 2a3362567a7..531d0dea7db 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index a3ce10c7f62..d5d51ddb3e8 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,6 +17,8 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
-{ oid => '1573', proname => 'pg_get_ruledef' }
+{ oid => '1573', proname => 'pg_get_ruledef' },
+{ oid => '1640', proname => 'pg_get_viewdef' },
+{ oid => '1641', proname => 'pg_get_viewdef' }
]
--
2.43.0
--zd8Z8rlPOcTi77n/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 31e773fb32e..328f994547e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -659,25 +659,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -717,31 +698,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index b935b6f14c0..166ae4b5645 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3962,13 +3962,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8519,12 +8512,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--eEEy3EHc57lA8spa
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 99ece0c1761..24c59510672 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 66cb016792c..c1b945cdae5 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8583,12 +8576,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--m23X5uHFNxthGTU3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 954f611de5b..8d81dcdc2f6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8593,15 +8586,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--GzYugJnip6WHHvTk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 45e4483692d..5b22fdc8e08 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--iWwo79nqhOvOs5kf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 49e92204bd6..b00ede45e41 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--AcCatzXgbvyipyEy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index febed53c9fa..c7adfad0e05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index de063d63b4f..7d576834d5c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index c215d47f2d8..2d1aa50dac6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,13 +3952,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8494,12 +8487,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.51.2
--IRGsBYp1UN8d6WrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c4d424ba10d..57b4adc0e2a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 597c468983e..9b87b9eda5f 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--3/nz5wg6+DYwHsLU
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
src/include/catalog/pg_retired.dat | 4 ++-
4 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 3733212fe0a..29557f3c9d2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 2a3362567a7..531d0dea7db 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index a3ce10c7f62..d5d51ddb3e8 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,6 +17,8 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
-{ oid => '1573', proname => 'pg_get_ruledef' }
+{ oid => '1573', proname => 'pg_get_ruledef' },
+{ oid => '1640', proname => 'pg_get_viewdef' },
+{ oid => '1641', proname => 'pg_get_viewdef' }
]
--
2.43.0
--zd8Z8rlPOcTi77n/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 31e773fb32e..328f994547e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -659,25 +659,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -717,31 +698,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index b935b6f14c0..166ae4b5645 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3962,13 +3962,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8519,12 +8512,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--eEEy3EHc57lA8spa
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 99ece0c1761..24c59510672 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 66cb016792c..c1b945cdae5 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8583,12 +8576,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--m23X5uHFNxthGTU3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 954f611de5b..8d81dcdc2f6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8593,15 +8586,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--GzYugJnip6WHHvTk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 49e92204bd6..b00ede45e41 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--AcCatzXgbvyipyEy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index febed53c9fa..c7adfad0e05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index de063d63b4f..7d576834d5c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index c215d47f2d8..2d1aa50dac6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,13 +3952,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8494,12 +8487,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.51.2
--IRGsBYp1UN8d6WrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c4d424ba10d..57b4adc0e2a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 597c468983e..9b87b9eda5f 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--3/nz5wg6+DYwHsLU
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
src/include/catalog/pg_retired.dat | 4 ++-
4 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 3733212fe0a..29557f3c9d2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 2a3362567a7..531d0dea7db 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index a3ce10c7f62..d5d51ddb3e8 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,6 +17,8 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
-{ oid => '1573', proname => 'pg_get_ruledef' }
+{ oid => '1573', proname => 'pg_get_ruledef' },
+{ oid => '1640', proname => 'pg_get_viewdef' },
+{ oid => '1641', proname => 'pg_get_viewdef' }
]
--
2.43.0
--zd8Z8rlPOcTi77n/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 99ece0c1761..24c59510672 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 66cb016792c..c1b945cdae5 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8583,12 +8576,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--m23X5uHFNxthGTU3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 954f611de5b..8d81dcdc2f6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8593,15 +8586,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--GzYugJnip6WHHvTk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 45e4483692d..5b22fdc8e08 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--iWwo79nqhOvOs5kf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index febed53c9fa..c7adfad0e05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index de063d63b4f..7d576834d5c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index c215d47f2d8..2d1aa50dac6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,13 +3952,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8494,12 +8487,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.51.2
--IRGsBYp1UN8d6WrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c4d424ba10d..57b4adc0e2a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 597c468983e..9b87b9eda5f 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--3/nz5wg6+DYwHsLU
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
src/include/catalog/pg_retired.dat | 4 ++-
4 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 3733212fe0a..29557f3c9d2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 2a3362567a7..531d0dea7db 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index a3ce10c7f62..d5d51ddb3e8 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,6 +17,8 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
-{ oid => '1573', proname => 'pg_get_ruledef' }
+{ oid => '1573', proname => 'pg_get_ruledef' },
+{ oid => '1640', proname => 'pg_get_viewdef' },
+{ oid => '1641', proname => 'pg_get_viewdef' }
]
--
2.43.0
--zd8Z8rlPOcTi77n/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 99ece0c1761..24c59510672 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 66cb016792c..c1b945cdae5 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8583,12 +8576,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--m23X5uHFNxthGTU3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 954f611de5b..8d81dcdc2f6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8593,15 +8586,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--GzYugJnip6WHHvTk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 45e4483692d..5b22fdc8e08 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--iWwo79nqhOvOs5kf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 49e92204bd6..b00ede45e41 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--AcCatzXgbvyipyEy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index febed53c9fa..c7adfad0e05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index de063d63b4f..7d576834d5c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index c215d47f2d8..2d1aa50dac6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,13 +3952,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8494,12 +8487,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.51.2
--IRGsBYp1UN8d6WrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c4d424ba10d..57b4adc0e2a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 597c468983e..9b87b9eda5f 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--3/nz5wg6+DYwHsLU
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
src/include/catalog/pg_retired.dat | 4 ++-
4 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 3733212fe0a..29557f3c9d2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 2a3362567a7..531d0dea7db 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index a3ce10c7f62..d5d51ddb3e8 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,6 +17,8 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
-{ oid => '1573', proname => 'pg_get_ruledef' }
+{ oid => '1573', proname => 'pg_get_ruledef' },
+{ oid => '1640', proname => 'pg_get_viewdef' },
+{ oid => '1641', proname => 'pg_get_viewdef' }
]
--
2.43.0
--zd8Z8rlPOcTi77n/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 99ece0c1761..24c59510672 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 66cb016792c..c1b945cdae5 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8583,12 +8576,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--m23X5uHFNxthGTU3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 954f611de5b..8d81dcdc2f6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8593,15 +8586,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--GzYugJnip6WHHvTk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 45e4483692d..5b22fdc8e08 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--iWwo79nqhOvOs5kf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 49e92204bd6..b00ede45e41 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--AcCatzXgbvyipyEy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index febed53c9fa..c7adfad0e05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index de063d63b4f..7d576834d5c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index c215d47f2d8..2d1aa50dac6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,13 +3952,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8494,12 +8487,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.51.2
--IRGsBYp1UN8d6WrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c4d424ba10d..57b4adc0e2a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 597c468983e..9b87b9eda5f 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--3/nz5wg6+DYwHsLU
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
src/include/catalog/pg_retired.dat | 4 ++-
4 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 3733212fe0a..29557f3c9d2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 2a3362567a7..531d0dea7db 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index a3ce10c7f62..d5d51ddb3e8 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,6 +17,8 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
-{ oid => '1573', proname => 'pg_get_ruledef' }
+{ oid => '1573', proname => 'pg_get_ruledef' },
+{ oid => '1640', proname => 'pg_get_viewdef' },
+{ oid => '1641', proname => 'pg_get_viewdef' }
]
--
2.43.0
--zd8Z8rlPOcTi77n/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 31e773fb32e..328f994547e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -659,25 +659,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -717,31 +698,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index b935b6f14c0..166ae4b5645 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3962,13 +3962,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8519,12 +8512,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--eEEy3EHc57lA8spa
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 99ece0c1761..24c59510672 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 66cb016792c..c1b945cdae5 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8583,12 +8576,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--m23X5uHFNxthGTU3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 954f611de5b..8d81dcdc2f6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8593,15 +8586,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--GzYugJnip6WHHvTk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 45e4483692d..5b22fdc8e08 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--iWwo79nqhOvOs5kf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 49e92204bd6..b00ede45e41 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--AcCatzXgbvyipyEy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index febed53c9fa..c7adfad0e05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index de063d63b4f..7d576834d5c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index c215d47f2d8..2d1aa50dac6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,13 +3952,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8494,12 +8487,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.51.2
--IRGsBYp1UN8d6WrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c4d424ba10d..57b4adc0e2a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 597c468983e..9b87b9eda5f 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--3/nz5wg6+DYwHsLU
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
src/include/catalog/pg_retired.dat | 4 ++-
4 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 3733212fe0a..29557f3c9d2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 2a3362567a7..531d0dea7db 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index a3ce10c7f62..d5d51ddb3e8 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,6 +17,8 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
-{ oid => '1573', proname => 'pg_get_ruledef' }
+{ oid => '1573', proname => 'pg_get_ruledef' },
+{ oid => '1640', proname => 'pg_get_viewdef' },
+{ oid => '1641', proname => 'pg_get_viewdef' }
]
--
2.43.0
--zd8Z8rlPOcTi77n/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 31e773fb32e..328f994547e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -659,25 +659,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -717,31 +698,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index b935b6f14c0..166ae4b5645 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3962,13 +3962,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8519,12 +8512,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--eEEy3EHc57lA8spa
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 99ece0c1761..24c59510672 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 66cb016792c..c1b945cdae5 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8583,12 +8576,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--m23X5uHFNxthGTU3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 954f611de5b..8d81dcdc2f6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8593,15 +8586,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--GzYugJnip6WHHvTk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 45e4483692d..5b22fdc8e08 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--iWwo79nqhOvOs5kf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 49e92204bd6..b00ede45e41 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--AcCatzXgbvyipyEy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index febed53c9fa..c7adfad0e05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index de063d63b4f..7d576834d5c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index c215d47f2d8..2d1aa50dac6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,13 +3952,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8494,12 +8487,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.51.2
--IRGsBYp1UN8d6WrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c4d424ba10d..57b4adc0e2a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 597c468983e..9b87b9eda5f 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--3/nz5wg6+DYwHsLU
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 31e773fb32e..328f994547e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -659,25 +659,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -717,31 +698,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index b935b6f14c0..166ae4b5645 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3962,13 +3962,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8519,12 +8512,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--eEEy3EHc57lA8spa
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 99ece0c1761..24c59510672 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 66cb016792c..c1b945cdae5 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8583,12 +8576,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--m23X5uHFNxthGTU3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 954f611de5b..8d81dcdc2f6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8593,15 +8586,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--GzYugJnip6WHHvTk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 45e4483692d..5b22fdc8e08 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--iWwo79nqhOvOs5kf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 49e92204bd6..b00ede45e41 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--AcCatzXgbvyipyEy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index febed53c9fa..c7adfad0e05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index de063d63b4f..7d576834d5c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index c215d47f2d8..2d1aa50dac6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,13 +3952,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8494,12 +8487,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.51.2
--IRGsBYp1UN8d6WrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c4d424ba10d..57b4adc0e2a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 597c468983e..9b87b9eda5f 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--3/nz5wg6+DYwHsLU
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
src/include/catalog/pg_retired.dat | 4 ++-
4 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 3733212fe0a..29557f3c9d2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 2a3362567a7..531d0dea7db 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index a3ce10c7f62..d5d51ddb3e8 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,6 +17,8 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
-{ oid => '1573', proname => 'pg_get_ruledef' }
+{ oid => '1573', proname => 'pg_get_ruledef' },
+{ oid => '1640', proname => 'pg_get_viewdef' },
+{ oid => '1641', proname => 'pg_get_viewdef' }
]
--
2.43.0
--zd8Z8rlPOcTi77n/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 31e773fb32e..328f994547e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -659,25 +659,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -717,31 +698,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index b935b6f14c0..166ae4b5645 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3962,13 +3962,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8519,12 +8512,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--eEEy3EHc57lA8spa
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 99ece0c1761..24c59510672 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 66cb016792c..c1b945cdae5 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8583,12 +8576,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--m23X5uHFNxthGTU3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 954f611de5b..8d81dcdc2f6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8593,15 +8586,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--GzYugJnip6WHHvTk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 45e4483692d..5b22fdc8e08 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--iWwo79nqhOvOs5kf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 49e92204bd6..b00ede45e41 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--AcCatzXgbvyipyEy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index febed53c9fa..c7adfad0e05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index de063d63b4f..7d576834d5c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index c215d47f2d8..2d1aa50dac6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,13 +3952,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8494,12 +8487,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.51.2
--IRGsBYp1UN8d6WrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index febed53c9fa..c7adfad0e05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index de063d63b4f..7d576834d5c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index c215d47f2d8..2d1aa50dac6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,13 +3952,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8494,12 +8487,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.51.2
--IRGsBYp1UN8d6WrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c4d424ba10d..57b4adc0e2a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 597c468983e..9b87b9eda5f 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--3/nz5wg6+DYwHsLU
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
src/include/catalog/pg_retired.dat | 4 ++-
4 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 3733212fe0a..29557f3c9d2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 2a3362567a7..531d0dea7db 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index a3ce10c7f62..d5d51ddb3e8 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,6 +17,8 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
-{ oid => '1573', proname => 'pg_get_ruledef' }
+{ oid => '1573', proname => 'pg_get_ruledef' },
+{ oid => '1640', proname => 'pg_get_viewdef' },
+{ oid => '1641', proname => 'pg_get_viewdef' }
]
--
2.43.0
--zd8Z8rlPOcTi77n/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 31e773fb32e..328f994547e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -659,25 +659,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -717,31 +698,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index b935b6f14c0..166ae4b5645 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3962,13 +3962,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8519,12 +8512,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--eEEy3EHc57lA8spa
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 99ece0c1761..24c59510672 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 66cb016792c..c1b945cdae5 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8583,12 +8576,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--m23X5uHFNxthGTU3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 954f611de5b..8d81dcdc2f6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8593,15 +8586,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--GzYugJnip6WHHvTk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 45e4483692d..5b22fdc8e08 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--iWwo79nqhOvOs5kf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 49e92204bd6..b00ede45e41 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--AcCatzXgbvyipyEy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index febed53c9fa..c7adfad0e05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index de063d63b4f..7d576834d5c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index c215d47f2d8..2d1aa50dac6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,13 +3952,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8494,12 +8487,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.51.2
--IRGsBYp1UN8d6WrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c4d424ba10d..57b4adc0e2a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 597c468983e..9b87b9eda5f 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--3/nz5wg6+DYwHsLU
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
src/include/catalog/pg_retired.dat | 4 ++-
4 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 3733212fe0a..29557f3c9d2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 2a3362567a7..531d0dea7db 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index a3ce10c7f62..d5d51ddb3e8 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,6 +17,8 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
-{ oid => '1573', proname => 'pg_get_ruledef' }
+{ oid => '1573', proname => 'pg_get_ruledef' },
+{ oid => '1640', proname => 'pg_get_viewdef' },
+{ oid => '1641', proname => 'pg_get_viewdef' }
]
--
2.43.0
--zd8Z8rlPOcTi77n/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 49e92204bd6..b00ede45e41 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--AcCatzXgbvyipyEy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index febed53c9fa..c7adfad0e05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index de063d63b4f..7d576834d5c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index c215d47f2d8..2d1aa50dac6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,13 +3952,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8494,12 +8487,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.51.2
--IRGsBYp1UN8d6WrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c4d424ba10d..57b4adc0e2a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 597c468983e..9b87b9eda5f 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--3/nz5wg6+DYwHsLU
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
src/include/catalog/pg_retired.dat | 4 ++-
4 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 3733212fe0a..29557f3c9d2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 2a3362567a7..531d0dea7db 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index a3ce10c7f62..d5d51ddb3e8 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,6 +17,8 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
-{ oid => '1573', proname => 'pg_get_ruledef' }
+{ oid => '1573', proname => 'pg_get_ruledef' },
+{ oid => '1640', proname => 'pg_get_viewdef' },
+{ oid => '1641', proname => 'pg_get_viewdef' }
]
--
2.43.0
--zd8Z8rlPOcTi77n/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 31e773fb32e..328f994547e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -659,25 +659,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -717,31 +698,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index b935b6f14c0..166ae4b5645 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3962,13 +3962,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8519,12 +8512,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--eEEy3EHc57lA8spa
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 99ece0c1761..24c59510672 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 66cb016792c..c1b945cdae5 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8583,12 +8576,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--m23X5uHFNxthGTU3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 954f611de5b..8d81dcdc2f6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8593,15 +8586,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--GzYugJnip6WHHvTk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 45e4483692d..5b22fdc8e08 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--iWwo79nqhOvOs5kf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 49e92204bd6..b00ede45e41 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--AcCatzXgbvyipyEy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index febed53c9fa..c7adfad0e05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index de063d63b4f..7d576834d5c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index c215d47f2d8..2d1aa50dac6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,13 +3952,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8494,12 +8487,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.51.2
--IRGsBYp1UN8d6WrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c4d424ba10d..57b4adc0e2a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 597c468983e..9b87b9eda5f 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--3/nz5wg6+DYwHsLU
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
src/include/catalog/pg_retired.dat | 4 ++-
4 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 3733212fe0a..29557f3c9d2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 2a3362567a7..531d0dea7db 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index a3ce10c7f62..d5d51ddb3e8 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,6 +17,8 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
-{ oid => '1573', proname => 'pg_get_ruledef' }
+{ oid => '1573', proname => 'pg_get_ruledef' },
+{ oid => '1640', proname => 'pg_get_viewdef' },
+{ oid => '1641', proname => 'pg_get_viewdef' }
]
--
2.43.0
--zd8Z8rlPOcTi77n/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 31e773fb32e..328f994547e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -659,25 +659,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -717,31 +698,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index b935b6f14c0..166ae4b5645 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3962,13 +3962,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8519,12 +8512,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--eEEy3EHc57lA8spa
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 99ece0c1761..24c59510672 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 66cb016792c..c1b945cdae5 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8583,12 +8576,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--m23X5uHFNxthGTU3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 954f611de5b..8d81dcdc2f6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8593,15 +8586,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--GzYugJnip6WHHvTk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 45e4483692d..5b22fdc8e08 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--iWwo79nqhOvOs5kf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c4d424ba10d..57b4adc0e2a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 597c468983e..9b87b9eda5f 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--3/nz5wg6+DYwHsLU
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
src/include/catalog/pg_retired.dat | 4 ++-
4 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 3733212fe0a..29557f3c9d2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 2a3362567a7..531d0dea7db 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index a3ce10c7f62..d5d51ddb3e8 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,6 +17,8 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
-{ oid => '1573', proname => 'pg_get_ruledef' }
+{ oid => '1573', proname => 'pg_get_ruledef' },
+{ oid => '1640', proname => 'pg_get_viewdef' },
+{ oid => '1641', proname => 'pg_get_viewdef' }
]
--
2.43.0
--zd8Z8rlPOcTi77n/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 99ece0c1761..24c59510672 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 66cb016792c..c1b945cdae5 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8583,12 +8576,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--m23X5uHFNxthGTU3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c4d424ba10d..57b4adc0e2a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 597c468983e..9b87b9eda5f 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--3/nz5wg6+DYwHsLU
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
src/include/catalog/pg_retired.dat | 4 ++-
4 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 3733212fe0a..29557f3c9d2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 2a3362567a7..531d0dea7db 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index a3ce10c7f62..d5d51ddb3e8 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,6 +17,8 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
-{ oid => '1573', proname => 'pg_get_ruledef' }
+{ oid => '1573', proname => 'pg_get_ruledef' },
+{ oid => '1640', proname => 'pg_get_viewdef' },
+{ oid => '1641', proname => 'pg_get_viewdef' }
]
--
2.43.0
--zd8Z8rlPOcTi77n/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 31e773fb32e..328f994547e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -659,25 +659,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -717,31 +698,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index b935b6f14c0..166ae4b5645 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3962,13 +3962,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8519,12 +8512,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--eEEy3EHc57lA8spa
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 99ece0c1761..24c59510672 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 66cb016792c..c1b945cdae5 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8583,12 +8576,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--m23X5uHFNxthGTU3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 954f611de5b..8d81dcdc2f6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8593,15 +8586,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--GzYugJnip6WHHvTk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 45e4483692d..5b22fdc8e08 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--iWwo79nqhOvOs5kf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 49e92204bd6..b00ede45e41 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--AcCatzXgbvyipyEy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index febed53c9fa..c7adfad0e05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index de063d63b4f..7d576834d5c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index c215d47f2d8..2d1aa50dac6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,13 +3952,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8494,12 +8487,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.51.2
--IRGsBYp1UN8d6WrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c4d424ba10d..57b4adc0e2a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 597c468983e..9b87b9eda5f 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--3/nz5wg6+DYwHsLU
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
src/include/catalog/pg_retired.dat | 4 ++-
4 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 3733212fe0a..29557f3c9d2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 2a3362567a7..531d0dea7db 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index a3ce10c7f62..d5d51ddb3e8 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,6 +17,8 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
-{ oid => '1573', proname => 'pg_get_ruledef' }
+{ oid => '1573', proname => 'pg_get_ruledef' },
+{ oid => '1640', proname => 'pg_get_viewdef' },
+{ oid => '1641', proname => 'pg_get_viewdef' }
]
--
2.43.0
--zd8Z8rlPOcTi77n/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 31e773fb32e..328f994547e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -659,25 +659,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -717,31 +698,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index b935b6f14c0..166ae4b5645 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3962,13 +3962,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8519,12 +8512,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--eEEy3EHc57lA8spa
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 954f611de5b..8d81dcdc2f6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8593,15 +8586,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--GzYugJnip6WHHvTk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 45e4483692d..5b22fdc8e08 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--iWwo79nqhOvOs5kf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 49e92204bd6..b00ede45e41 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--AcCatzXgbvyipyEy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c4d424ba10d..57b4adc0e2a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 597c468983e..9b87b9eda5f 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--3/nz5wg6+DYwHsLU
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
src/include/catalog/pg_retired.dat | 4 ++-
4 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 3733212fe0a..29557f3c9d2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 2a3362567a7..531d0dea7db 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index a3ce10c7f62..d5d51ddb3e8 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,6 +17,8 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
-{ oid => '1573', proname => 'pg_get_ruledef' }
+{ oid => '1573', proname => 'pg_get_ruledef' },
+{ oid => '1640', proname => 'pg_get_viewdef' },
+{ oid => '1641', proname => 'pg_get_viewdef' }
]
--
2.43.0
--zd8Z8rlPOcTi77n/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 31e773fb32e..328f994547e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -659,25 +659,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -717,31 +698,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index b935b6f14c0..166ae4b5645 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3962,13 +3962,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8519,12 +8512,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--eEEy3EHc57lA8spa
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 99ece0c1761..24c59510672 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 66cb016792c..c1b945cdae5 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8583,12 +8576,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--m23X5uHFNxthGTU3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 954f611de5b..8d81dcdc2f6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8593,15 +8586,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--GzYugJnip6WHHvTk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 49e92204bd6..b00ede45e41 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--AcCatzXgbvyipyEy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index febed53c9fa..c7adfad0e05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index de063d63b4f..7d576834d5c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index c215d47f2d8..2d1aa50dac6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,13 +3952,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8494,12 +8487,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.51.2
--IRGsBYp1UN8d6WrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c4d424ba10d..57b4adc0e2a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 597c468983e..9b87b9eda5f 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--3/nz5wg6+DYwHsLU
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
src/include/catalog/pg_retired.dat | 4 ++-
4 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 3733212fe0a..29557f3c9d2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 2a3362567a7..531d0dea7db 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index a3ce10c7f62..d5d51ddb3e8 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,6 +17,8 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
-{ oid => '1573', proname => 'pg_get_ruledef' }
+{ oid => '1573', proname => 'pg_get_ruledef' },
+{ oid => '1640', proname => 'pg_get_viewdef' },
+{ oid => '1641', proname => 'pg_get_viewdef' }
]
--
2.43.0
--zd8Z8rlPOcTi77n/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 99ece0c1761..24c59510672 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 66cb016792c..c1b945cdae5 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8583,12 +8576,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--m23X5uHFNxthGTU3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 954f611de5b..8d81dcdc2f6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8593,15 +8586,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--GzYugJnip6WHHvTk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 49e92204bd6..b00ede45e41 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--AcCatzXgbvyipyEy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index febed53c9fa..c7adfad0e05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index de063d63b4f..7d576834d5c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index c215d47f2d8..2d1aa50dac6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,13 +3952,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8494,12 +8487,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.51.2
--IRGsBYp1UN8d6WrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c4d424ba10d..57b4adc0e2a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 597c468983e..9b87b9eda5f 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--3/nz5wg6+DYwHsLU
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
src/include/catalog/pg_retired.dat | 4 ++-
4 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 3733212fe0a..29557f3c9d2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 2a3362567a7..531d0dea7db 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index a3ce10c7f62..d5d51ddb3e8 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,6 +17,8 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
-{ oid => '1573', proname => 'pg_get_ruledef' }
+{ oid => '1573', proname => 'pg_get_ruledef' },
+{ oid => '1640', proname => 'pg_get_viewdef' },
+{ oid => '1641', proname => 'pg_get_viewdef' }
]
--
2.43.0
--zd8Z8rlPOcTi77n/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 31e773fb32e..328f994547e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -659,25 +659,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -717,31 +698,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index b935b6f14c0..166ae4b5645 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3962,13 +3962,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8519,12 +8512,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--eEEy3EHc57lA8spa
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 99ece0c1761..24c59510672 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 66cb016792c..c1b945cdae5 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8583,12 +8576,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--m23X5uHFNxthGTU3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 954f611de5b..8d81dcdc2f6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8593,15 +8586,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--GzYugJnip6WHHvTk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 49e92204bd6..b00ede45e41 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--AcCatzXgbvyipyEy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index febed53c9fa..c7adfad0e05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index de063d63b4f..7d576834d5c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index c215d47f2d8..2d1aa50dac6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,13 +3952,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8494,12 +8487,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.51.2
--IRGsBYp1UN8d6WrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c4d424ba10d..57b4adc0e2a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 597c468983e..9b87b9eda5f 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--3/nz5wg6+DYwHsLU
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
src/include/catalog/pg_retired.dat | 4 ++-
4 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 3733212fe0a..29557f3c9d2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 2a3362567a7..531d0dea7db 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index a3ce10c7f62..d5d51ddb3e8 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,6 +17,8 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
-{ oid => '1573', proname => 'pg_get_ruledef' }
+{ oid => '1573', proname => 'pg_get_ruledef' },
+{ oid => '1640', proname => 'pg_get_viewdef' },
+{ oid => '1641', proname => 'pg_get_viewdef' }
]
--
2.43.0
--zd8Z8rlPOcTi77n/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 99ece0c1761..24c59510672 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 66cb016792c..c1b945cdae5 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8583,12 +8576,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--m23X5uHFNxthGTU3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 954f611de5b..8d81dcdc2f6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8593,15 +8586,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--GzYugJnip6WHHvTk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 45e4483692d..5b22fdc8e08 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--iWwo79nqhOvOs5kf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 49e92204bd6..b00ede45e41 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--AcCatzXgbvyipyEy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index febed53c9fa..c7adfad0e05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index de063d63b4f..7d576834d5c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index c215d47f2d8..2d1aa50dac6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,13 +3952,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8494,12 +8487,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.51.2
--IRGsBYp1UN8d6WrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c4d424ba10d..57b4adc0e2a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 597c468983e..9b87b9eda5f 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--3/nz5wg6+DYwHsLU
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
src/include/catalog/pg_retired.dat | 4 ++-
4 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 3733212fe0a..29557f3c9d2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 2a3362567a7..531d0dea7db 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index a3ce10c7f62..d5d51ddb3e8 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,6 +17,8 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
-{ oid => '1573', proname => 'pg_get_ruledef' }
+{ oid => '1573', proname => 'pg_get_ruledef' },
+{ oid => '1640', proname => 'pg_get_viewdef' },
+{ oid => '1641', proname => 'pg_get_viewdef' }
]
--
2.43.0
--zd8Z8rlPOcTi77n/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 99ece0c1761..24c59510672 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 66cb016792c..c1b945cdae5 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8583,12 +8576,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--m23X5uHFNxthGTU3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 954f611de5b..8d81dcdc2f6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8593,15 +8586,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--GzYugJnip6WHHvTk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 45e4483692d..5b22fdc8e08 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--iWwo79nqhOvOs5kf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 49e92204bd6..b00ede45e41 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--AcCatzXgbvyipyEy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index febed53c9fa..c7adfad0e05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index de063d63b4f..7d576834d5c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index c215d47f2d8..2d1aa50dac6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,13 +3952,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8494,12 +8487,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.51.2
--IRGsBYp1UN8d6WrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c4d424ba10d..57b4adc0e2a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 597c468983e..9b87b9eda5f 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--3/nz5wg6+DYwHsLU
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
src/include/catalog/pg_retired.dat | 4 ++-
4 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 3733212fe0a..29557f3c9d2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 2a3362567a7..531d0dea7db 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index a3ce10c7f62..d5d51ddb3e8 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,6 +17,8 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
-{ oid => '1573', proname => 'pg_get_ruledef' }
+{ oid => '1573', proname => 'pg_get_ruledef' },
+{ oid => '1640', proname => 'pg_get_viewdef' },
+{ oid => '1641', proname => 'pg_get_viewdef' }
]
--
2.43.0
--zd8Z8rlPOcTi77n/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 31e773fb32e..328f994547e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -659,25 +659,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -717,31 +698,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index b935b6f14c0..166ae4b5645 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3962,13 +3962,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8519,12 +8512,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--eEEy3EHc57lA8spa
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 99ece0c1761..24c59510672 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 66cb016792c..c1b945cdae5 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8583,12 +8576,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--m23X5uHFNxthGTU3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 954f611de5b..8d81dcdc2f6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8593,15 +8586,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--GzYugJnip6WHHvTk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 45e4483692d..5b22fdc8e08 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--iWwo79nqhOvOs5kf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 49e92204bd6..b00ede45e41 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--AcCatzXgbvyipyEy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c4d424ba10d..57b4adc0e2a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 597c468983e..9b87b9eda5f 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--3/nz5wg6+DYwHsLU
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index febed53c9fa..c7adfad0e05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index de063d63b4f..7d576834d5c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index c215d47f2d8..2d1aa50dac6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,13 +3952,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8494,12 +8487,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.51.2
--IRGsBYp1UN8d6WrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c4d424ba10d..57b4adc0e2a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 597c468983e..9b87b9eda5f 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--3/nz5wg6+DYwHsLU
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
src/include/catalog/pg_retired.dat | 4 ++-
4 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 3733212fe0a..29557f3c9d2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 2a3362567a7..531d0dea7db 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index a3ce10c7f62..d5d51ddb3e8 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,6 +17,8 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
-{ oid => '1573', proname => 'pg_get_ruledef' }
+{ oid => '1573', proname => 'pg_get_ruledef' },
+{ oid => '1640', proname => 'pg_get_viewdef' },
+{ oid => '1641', proname => 'pg_get_viewdef' }
]
--
2.43.0
--zd8Z8rlPOcTi77n/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 31e773fb32e..328f994547e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -659,25 +659,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -717,31 +698,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index b935b6f14c0..166ae4b5645 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3962,13 +3962,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8519,12 +8512,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--eEEy3EHc57lA8spa
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 99ece0c1761..24c59510672 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 66cb016792c..c1b945cdae5 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8583,12 +8576,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--m23X5uHFNxthGTU3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 954f611de5b..8d81dcdc2f6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8593,15 +8586,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--GzYugJnip6WHHvTk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 45e4483692d..5b22fdc8e08 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--iWwo79nqhOvOs5kf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 49e92204bd6..b00ede45e41 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--AcCatzXgbvyipyEy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index febed53c9fa..c7adfad0e05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index de063d63b4f..7d576834d5c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index c215d47f2d8..2d1aa50dac6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,13 +3952,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8494,12 +8487,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.51.2
--IRGsBYp1UN8d6WrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c4d424ba10d..57b4adc0e2a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 597c468983e..9b87b9eda5f 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--3/nz5wg6+DYwHsLU
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
src/include/catalog/pg_retired.dat | 4 ++-
4 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 3733212fe0a..29557f3c9d2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 2a3362567a7..531d0dea7db 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index a3ce10c7f62..d5d51ddb3e8 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,6 +17,8 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
-{ oid => '1573', proname => 'pg_get_ruledef' }
+{ oid => '1573', proname => 'pg_get_ruledef' },
+{ oid => '1640', proname => 'pg_get_viewdef' },
+{ oid => '1641', proname => 'pg_get_viewdef' }
]
--
2.43.0
--zd8Z8rlPOcTi77n/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 31e773fb32e..328f994547e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -659,25 +659,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -717,31 +698,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index b935b6f14c0..166ae4b5645 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3962,13 +3962,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8519,12 +8512,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--eEEy3EHc57lA8spa
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 99ece0c1761..24c59510672 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 66cb016792c..c1b945cdae5 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8583,12 +8576,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--m23X5uHFNxthGTU3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 954f611de5b..8d81dcdc2f6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8593,15 +8586,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--GzYugJnip6WHHvTk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 45e4483692d..5b22fdc8e08 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--iWwo79nqhOvOs5kf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 49e92204bd6..b00ede45e41 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--AcCatzXgbvyipyEy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index febed53c9fa..c7adfad0e05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index de063d63b4f..7d576834d5c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index c215d47f2d8..2d1aa50dac6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,13 +3952,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8494,12 +8487,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.51.2
--IRGsBYp1UN8d6WrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c4d424ba10d..57b4adc0e2a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 597c468983e..9b87b9eda5f 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--3/nz5wg6+DYwHsLU
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
src/include/catalog/pg_retired.dat | 4 ++-
4 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 3733212fe0a..29557f3c9d2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 2a3362567a7..531d0dea7db 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index a3ce10c7f62..d5d51ddb3e8 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,6 +17,8 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
-{ oid => '1573', proname => 'pg_get_ruledef' }
+{ oid => '1573', proname => 'pg_get_ruledef' },
+{ oid => '1640', proname => 'pg_get_viewdef' },
+{ oid => '1641', proname => 'pg_get_viewdef' }
]
--
2.43.0
--zd8Z8rlPOcTi77n/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 31e773fb32e..328f994547e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -659,25 +659,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -717,31 +698,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index b935b6f14c0..166ae4b5645 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3962,13 +3962,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8519,12 +8512,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--eEEy3EHc57lA8spa
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 99ece0c1761..24c59510672 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 66cb016792c..c1b945cdae5 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8583,12 +8576,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--m23X5uHFNxthGTU3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 954f611de5b..8d81dcdc2f6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8593,15 +8586,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--GzYugJnip6WHHvTk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 45e4483692d..5b22fdc8e08 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--iWwo79nqhOvOs5kf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 49e92204bd6..b00ede45e41 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--AcCatzXgbvyipyEy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index febed53c9fa..c7adfad0e05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index de063d63b4f..7d576834d5c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index c215d47f2d8..2d1aa50dac6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,13 +3952,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8494,12 +8487,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.51.2
--IRGsBYp1UN8d6WrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c4d424ba10d..57b4adc0e2a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 597c468983e..9b87b9eda5f 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--3/nz5wg6+DYwHsLU
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
src/include/catalog/pg_retired.dat | 4 ++-
4 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 3733212fe0a..29557f3c9d2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 2a3362567a7..531d0dea7db 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index a3ce10c7f62..d5d51ddb3e8 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,6 +17,8 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
-{ oid => '1573', proname => 'pg_get_ruledef' }
+{ oid => '1573', proname => 'pg_get_ruledef' },
+{ oid => '1640', proname => 'pg_get_viewdef' },
+{ oid => '1641', proname => 'pg_get_viewdef' }
]
--
2.43.0
--zd8Z8rlPOcTi77n/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 31e773fb32e..328f994547e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -659,25 +659,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -717,31 +698,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index b935b6f14c0..166ae4b5645 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3962,13 +3962,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8519,12 +8512,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--eEEy3EHc57lA8spa
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 99ece0c1761..24c59510672 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 66cb016792c..c1b945cdae5 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8583,12 +8576,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--m23X5uHFNxthGTU3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 954f611de5b..8d81dcdc2f6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8593,15 +8586,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--GzYugJnip6WHHvTk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 45e4483692d..5b22fdc8e08 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--iWwo79nqhOvOs5kf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 49e92204bd6..b00ede45e41 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--AcCatzXgbvyipyEy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index febed53c9fa..c7adfad0e05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index de063d63b4f..7d576834d5c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index c215d47f2d8..2d1aa50dac6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,13 +3952,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8494,12 +8487,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.51.2
--IRGsBYp1UN8d6WrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
src/include/catalog/pg_retired.dat | 4 ++-
4 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 3733212fe0a..29557f3c9d2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 2a3362567a7..531d0dea7db 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index a3ce10c7f62..d5d51ddb3e8 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,6 +17,8 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
-{ oid => '1573', proname => 'pg_get_ruledef' }
+{ oid => '1573', proname => 'pg_get_ruledef' },
+{ oid => '1640', proname => 'pg_get_viewdef' },
+{ oid => '1641', proname => 'pg_get_viewdef' }
]
--
2.43.0
--zd8Z8rlPOcTi77n/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 31e773fb32e..328f994547e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -659,25 +659,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -717,31 +698,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index b935b6f14c0..166ae4b5645 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3962,13 +3962,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8519,12 +8512,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--eEEy3EHc57lA8spa
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 954f611de5b..8d81dcdc2f6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8593,15 +8586,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--GzYugJnip6WHHvTk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 45e4483692d..5b22fdc8e08 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--iWwo79nqhOvOs5kf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 49e92204bd6..b00ede45e41 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--AcCatzXgbvyipyEy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 45e4483692d..5b22fdc8e08 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--iWwo79nqhOvOs5kf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index febed53c9fa..c7adfad0e05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index de063d63b4f..7d576834d5c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index c215d47f2d8..2d1aa50dac6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,13 +3952,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8494,12 +8487,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.51.2
--IRGsBYp1UN8d6WrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c4d424ba10d..57b4adc0e2a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 597c468983e..9b87b9eda5f 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--3/nz5wg6+DYwHsLU
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
src/include/catalog/pg_retired.dat | 4 ++-
4 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 3733212fe0a..29557f3c9d2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 2a3362567a7..531d0dea7db 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index a3ce10c7f62..d5d51ddb3e8 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,6 +17,8 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
-{ oid => '1573', proname => 'pg_get_ruledef' }
+{ oid => '1573', proname => 'pg_get_ruledef' },
+{ oid => '1640', proname => 'pg_get_viewdef' },
+{ oid => '1641', proname => 'pg_get_viewdef' }
]
--
2.43.0
--zd8Z8rlPOcTi77n/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 31e773fb32e..328f994547e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -659,25 +659,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -717,31 +698,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index b935b6f14c0..166ae4b5645 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3962,13 +3962,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8519,12 +8512,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--eEEy3EHc57lA8spa
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 99ece0c1761..24c59510672 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 66cb016792c..c1b945cdae5 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8583,12 +8576,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--m23X5uHFNxthGTU3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 954f611de5b..8d81dcdc2f6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8593,15 +8586,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--GzYugJnip6WHHvTk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 45e4483692d..5b22fdc8e08 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--iWwo79nqhOvOs5kf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 49e92204bd6..b00ede45e41 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--AcCatzXgbvyipyEy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 31e773fb32e..328f994547e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -659,25 +659,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -717,31 +698,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index b935b6f14c0..166ae4b5645 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3962,13 +3962,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8519,12 +8512,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--eEEy3EHc57lA8spa
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 49e92204bd6..b00ede45e41 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--AcCatzXgbvyipyEy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index febed53c9fa..c7adfad0e05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index de063d63b4f..7d576834d5c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index c215d47f2d8..2d1aa50dac6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,13 +3952,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8494,12 +8487,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.51.2
--IRGsBYp1UN8d6WrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c4d424ba10d..57b4adc0e2a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 597c468983e..9b87b9eda5f 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--3/nz5wg6+DYwHsLU
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
src/include/catalog/pg_retired.dat | 4 ++-
4 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 3733212fe0a..29557f3c9d2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 2a3362567a7..531d0dea7db 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index a3ce10c7f62..d5d51ddb3e8 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,6 +17,8 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
-{ oid => '1573', proname => 'pg_get_ruledef' }
+{ oid => '1573', proname => 'pg_get_ruledef' },
+{ oid => '1640', proname => 'pg_get_viewdef' },
+{ oid => '1641', proname => 'pg_get_viewdef' }
]
--
2.43.0
--zd8Z8rlPOcTi77n/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 31e773fb32e..328f994547e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -659,25 +659,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -717,31 +698,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index b935b6f14c0..166ae4b5645 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3962,13 +3962,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8519,12 +8512,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--eEEy3EHc57lA8spa
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 99ece0c1761..24c59510672 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 66cb016792c..c1b945cdae5 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8583,12 +8576,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--m23X5uHFNxthGTU3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 954f611de5b..8d81dcdc2f6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8593,15 +8586,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--GzYugJnip6WHHvTk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 45e4483692d..5b22fdc8e08 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--iWwo79nqhOvOs5kf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 49e92204bd6..b00ede45e41 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--AcCatzXgbvyipyEy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index febed53c9fa..c7adfad0e05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index de063d63b4f..7d576834d5c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index c215d47f2d8..2d1aa50dac6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,13 +3952,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8494,12 +8487,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.51.2
--IRGsBYp1UN8d6WrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c4d424ba10d..57b4adc0e2a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 597c468983e..9b87b9eda5f 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--3/nz5wg6+DYwHsLU
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
src/include/catalog/pg_retired.dat | 4 ++-
4 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 3733212fe0a..29557f3c9d2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 2a3362567a7..531d0dea7db 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index a3ce10c7f62..d5d51ddb3e8 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,6 +17,8 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
-{ oid => '1573', proname => 'pg_get_ruledef' }
+{ oid => '1573', proname => 'pg_get_ruledef' },
+{ oid => '1640', proname => 'pg_get_viewdef' },
+{ oid => '1641', proname => 'pg_get_viewdef' }
]
--
2.43.0
--zd8Z8rlPOcTi77n/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 31e773fb32e..328f994547e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -659,25 +659,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -717,31 +698,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index b935b6f14c0..166ae4b5645 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3962,13 +3962,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8519,12 +8512,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--eEEy3EHc57lA8spa
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 45e4483692d..5b22fdc8e08 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--iWwo79nqhOvOs5kf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 49e92204bd6..b00ede45e41 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--AcCatzXgbvyipyEy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 31e773fb32e..328f994547e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -659,25 +659,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -717,31 +698,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index b935b6f14c0..166ae4b5645 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3962,13 +3962,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8519,12 +8512,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--eEEy3EHc57lA8spa
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index febed53c9fa..c7adfad0e05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index de063d63b4f..7d576834d5c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index c215d47f2d8..2d1aa50dac6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,13 +3952,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8494,12 +8487,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.51.2
--IRGsBYp1UN8d6WrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c4d424ba10d..57b4adc0e2a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 597c468983e..9b87b9eda5f 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--3/nz5wg6+DYwHsLU
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
src/include/catalog/pg_retired.dat | 4 ++-
4 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 3733212fe0a..29557f3c9d2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 2a3362567a7..531d0dea7db 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index a3ce10c7f62..d5d51ddb3e8 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,6 +17,8 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
-{ oid => '1573', proname => 'pg_get_ruledef' }
+{ oid => '1573', proname => 'pg_get_ruledef' },
+{ oid => '1640', proname => 'pg_get_viewdef' },
+{ oid => '1641', proname => 'pg_get_viewdef' }
]
--
2.43.0
--zd8Z8rlPOcTi77n/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 31e773fb32e..328f994547e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -659,25 +659,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -717,31 +698,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index b935b6f14c0..166ae4b5645 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3962,13 +3962,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8519,12 +8512,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--eEEy3EHc57lA8spa
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 99ece0c1761..24c59510672 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 66cb016792c..c1b945cdae5 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8583,12 +8576,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--m23X5uHFNxthGTU3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 954f611de5b..8d81dcdc2f6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8593,15 +8586,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--GzYugJnip6WHHvTk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 45e4483692d..5b22fdc8e08 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--iWwo79nqhOvOs5kf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 49e92204bd6..b00ede45e41 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--AcCatzXgbvyipyEy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c4d424ba10d..57b4adc0e2a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 597c468983e..9b87b9eda5f 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--3/nz5wg6+DYwHsLU
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
src/include/catalog/pg_retired.dat | 4 ++-
4 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 3733212fe0a..29557f3c9d2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 2a3362567a7..531d0dea7db 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index a3ce10c7f62..d5d51ddb3e8 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,6 +17,8 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
-{ oid => '1573', proname => 'pg_get_ruledef' }
+{ oid => '1573', proname => 'pg_get_ruledef' },
+{ oid => '1640', proname => 'pg_get_viewdef' },
+{ oid => '1641', proname => 'pg_get_viewdef' }
]
--
2.43.0
--zd8Z8rlPOcTi77n/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 99ece0c1761..24c59510672 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 66cb016792c..c1b945cdae5 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8583,12 +8576,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--m23X5uHFNxthGTU3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 954f611de5b..8d81dcdc2f6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8593,15 +8586,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--GzYugJnip6WHHvTk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 45e4483692d..5b22fdc8e08 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--iWwo79nqhOvOs5kf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 49e92204bd6..b00ede45e41 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--AcCatzXgbvyipyEy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 31e773fb32e..328f994547e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -659,25 +659,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -717,31 +698,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index b935b6f14c0..166ae4b5645 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3962,13 +3962,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8519,12 +8512,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--eEEy3EHc57lA8spa
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index febed53c9fa..c7adfad0e05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index de063d63b4f..7d576834d5c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index c215d47f2d8..2d1aa50dac6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,13 +3952,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8494,12 +8487,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.51.2
--IRGsBYp1UN8d6WrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c4d424ba10d..57b4adc0e2a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 597c468983e..9b87b9eda5f 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--3/nz5wg6+DYwHsLU
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
src/include/catalog/pg_retired.dat | 4 ++-
4 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 3733212fe0a..29557f3c9d2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 2a3362567a7..531d0dea7db 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index a3ce10c7f62..d5d51ddb3e8 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,6 +17,8 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
-{ oid => '1573', proname => 'pg_get_ruledef' }
+{ oid => '1573', proname => 'pg_get_ruledef' },
+{ oid => '1640', proname => 'pg_get_viewdef' },
+{ oid => '1641', proname => 'pg_get_viewdef' }
]
--
2.43.0
--zd8Z8rlPOcTi77n/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 31e773fb32e..328f994547e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -659,25 +659,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -717,31 +698,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index b935b6f14c0..166ae4b5645 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3962,13 +3962,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8519,12 +8512,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--eEEy3EHc57lA8spa
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 99ece0c1761..24c59510672 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 66cb016792c..c1b945cdae5 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8583,12 +8576,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--m23X5uHFNxthGTU3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 954f611de5b..8d81dcdc2f6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8593,15 +8586,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--GzYugJnip6WHHvTk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 45e4483692d..5b22fdc8e08 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--iWwo79nqhOvOs5kf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 49e92204bd6..b00ede45e41 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--AcCatzXgbvyipyEy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
src/include/catalog/pg_retired.dat | 4 ++-
4 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 3733212fe0a..29557f3c9d2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 2a3362567a7..531d0dea7db 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index a3ce10c7f62..d5d51ddb3e8 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,6 +17,8 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
-{ oid => '1573', proname => 'pg_get_ruledef' }
+{ oid => '1573', proname => 'pg_get_ruledef' },
+{ oid => '1640', proname => 'pg_get_viewdef' },
+{ oid => '1641', proname => 'pg_get_viewdef' }
]
--
2.43.0
--zd8Z8rlPOcTi77n/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 99ece0c1761..24c59510672 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 66cb016792c..c1b945cdae5 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8583,12 +8576,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--m23X5uHFNxthGTU3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 954f611de5b..8d81dcdc2f6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8593,15 +8586,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--GzYugJnip6WHHvTk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 31e773fb32e..328f994547e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -659,25 +659,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -717,31 +698,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index b935b6f14c0..166ae4b5645 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3962,13 +3962,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8519,12 +8512,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--eEEy3EHc57lA8spa
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 45e4483692d..5b22fdc8e08 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--iWwo79nqhOvOs5kf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index febed53c9fa..c7adfad0e05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index de063d63b4f..7d576834d5c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index c215d47f2d8..2d1aa50dac6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,13 +3952,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8494,12 +8487,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.51.2
--IRGsBYp1UN8d6WrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 99ece0c1761..24c59510672 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 66cb016792c..c1b945cdae5 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8583,12 +8576,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--m23X5uHFNxthGTU3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index febed53c9fa..c7adfad0e05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index de063d63b4f..7d576834d5c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index c215d47f2d8..2d1aa50dac6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,13 +3952,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8494,12 +8487,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.51.2
--IRGsBYp1UN8d6WrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 45e4483692d..5b22fdc8e08 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--iWwo79nqhOvOs5kf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 31e773fb32e..328f994547e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -659,25 +659,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -717,31 +698,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index b935b6f14c0..166ae4b5645 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3962,13 +3962,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8519,12 +8512,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--eEEy3EHc57lA8spa
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 45e4483692d..5b22fdc8e08 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--iWwo79nqhOvOs5kf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 45e4483692d..5b22fdc8e08 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--iWwo79nqhOvOs5kf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 31e773fb32e..328f994547e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -659,25 +659,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -717,31 +698,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index b935b6f14c0..166ae4b5645 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3962,13 +3962,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8519,12 +8512,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--eEEy3EHc57lA8spa
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 31e773fb32e..328f994547e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -659,25 +659,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -717,31 +698,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index b935b6f14c0..166ae4b5645 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3962,13 +3962,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8519,12 +8512,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--eEEy3EHc57lA8spa
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index febed53c9fa..c7adfad0e05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index de063d63b4f..7d576834d5c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index c215d47f2d8..2d1aa50dac6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,13 +3952,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8494,12 +8487,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.51.2
--IRGsBYp1UN8d6WrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c4d424ba10d..57b4adc0e2a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 597c468983e..9b87b9eda5f 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--3/nz5wg6+DYwHsLU
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 99ece0c1761..24c59510672 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 66cb016792c..c1b945cdae5 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8583,12 +8576,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--m23X5uHFNxthGTU3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 99ece0c1761..24c59510672 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 66cb016792c..c1b945cdae5 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8583,12 +8576,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--m23X5uHFNxthGTU3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 954f611de5b..8d81dcdc2f6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8593,15 +8586,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--GzYugJnip6WHHvTk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 31e773fb32e..328f994547e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -659,25 +659,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -717,31 +698,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index b935b6f14c0..166ae4b5645 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3962,13 +3962,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8519,12 +8512,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--eEEy3EHc57lA8spa
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index febed53c9fa..c7adfad0e05 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index de063d63b4f..7d576834d5c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index c215d47f2d8..2d1aa50dac6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3952,13 +3952,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8494,12 +8487,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.51.2
--IRGsBYp1UN8d6WrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v1-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c4d424ba10d..57b4adc0e2a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 597c468983e..9b87b9eda5f 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--3/nz5wg6+DYwHsLU
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
src/include/catalog/pg_retired.dat | 4 ++-
4 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 3733212fe0a..29557f3c9d2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 2a3362567a7..531d0dea7db 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index a3ce10c7f62..d5d51ddb3e8 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,6 +17,8 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
-{ oid => '1573', proname => 'pg_get_ruledef' }
+{ oid => '1573', proname => 'pg_get_ruledef' },
+{ oid => '1640', proname => 'pg_get_viewdef' },
+{ oid => '1641', proname => 'pg_get_viewdef' }
]
--
2.43.0
--zd8Z8rlPOcTi77n/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 31e773fb32e..328f994547e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -659,25 +659,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -717,31 +698,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index b935b6f14c0..166ae4b5645 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3962,13 +3962,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8519,12 +8512,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--eEEy3EHc57lA8spa
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 99ece0c1761..24c59510672 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 66cb016792c..c1b945cdae5 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8583,12 +8576,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--m23X5uHFNxthGTU3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 49e92204bd6..b00ede45e41 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--AcCatzXgbvyipyEy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 31e773fb32e..328f994547e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -659,25 +659,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -717,31 +698,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index b935b6f14c0..166ae4b5645 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3962,13 +3962,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8519,12 +8512,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--eEEy3EHc57lA8spa
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v4-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
2 files changed, 4 insertions(+), 53 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 99ece0c1761..24c59510672 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 66cb016792c..c1b945cdae5 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3975,13 +3975,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8583,12 +8576,14 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--m23X5uHFNxthGTU3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v5-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6a4c7e4822d..1202cb07c07 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 954f611de5b..8d81dcdc2f6 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '8302', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8593,15 +8586,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.52.0
--GzYugJnip6WHHvTk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v7-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
3 files changed, 16 insertions(+), 53 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c4d424ba10d..57b4adc0e2a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 597c468983e..9b87b9eda5f 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.43.0
--3/nz5wg6+DYwHsLU
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v2-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
src/include/catalog/pg_retired.dat | 4 ++-
4 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 3aad2fbf8f3..4ddbf194fa8 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -664,6 +664,20 @@ LANGUAGE INTERNAL
PARALLEL SAFE
AS 'pg_get_ruledef';
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view text, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef_name';
+
+CREATE OR REPLACE FUNCTION
+ pg_get_viewdef(view oid, pretty bool DEFAULT false)
+RETURNS TEXT
+LANGUAGE INTERNAL
+PARALLEL RESTRICTED
+AS 'pg_get_viewdef';
+
--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 3733212fe0a..29557f3c9d2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -658,25 +658,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -716,31 +697,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 2a3362567a7..531d0dea7db 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3961,13 +3961,6 @@
proargtypes => 'oid oid', prosrc => 'oidge' },
# System-view support functions
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8510,12 +8503,12 @@
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
descr => 'select statement of a view with pretty-print option',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat
index a3ce10c7f62..d5d51ddb3e8 100644
--- a/src/include/catalog/pg_retired.dat
+++ b/src/include/catalog/pg_retired.dat
@@ -17,6 +17,8 @@
# At the same time, it may be good to be reminded what procedure was associated
# with it.
-{ oid => '1573', proname => 'pg_get_ruledef' }
+{ oid => '1573', proname => 'pg_get_ruledef' },
+{ oid => '1640', proname => 'pg_get_viewdef' },
+{ oid => '1641', proname => 'pg_get_viewdef' }
]
--
2.43.0
--zd8Z8rlPOcTi77n/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v3-0004-Handle-pg_get_indexdef-default-args-in-system_fun.patch"
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 45e4483692d..5b22fdc8e08 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}',prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--iWwo79nqhOvOs5kf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8-0003-Handle-pg_get_indexdef-default-args-in-system_fun.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql
@ 2025-12-09 17:33 Mark Wong <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
text *viewname = PG_GETARG_TEXT_PP(0);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 49e92204bd6..b00ede45e41 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3981,13 +3981,6 @@
{ oid => '6469', descr => 'source text of a property graph',
proname => 'pg_get_propgraphdef', provolatile => 's', prorettype => 'text',
proargtypes => 'oid', prosrc => 'pg_get_propgraphdef' },
-{ oid => '1640', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'text',
- prosrc => 'pg_get_viewdef_name' },
-{ oid => '1641', descr => 'select statement of a view',
- proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
- prorettype => 'text', proargtypes => 'oid', prosrc => 'pg_get_viewdef' },
{ oid => '1642', descr => 'role name by OID (with fallback)',
proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name',
proargtypes => 'oid', prosrc => 'pg_get_userbyid' },
@@ -8567,15 +8560,17 @@
proargtypes => 'oid bool', proargnames => '{rule,pretty}',
proargdefaults => '{false}', prosrc => 'pg_get_ruledef' },
{ oid => '2505',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'text bool',
- prosrc => 'pg_get_viewdef_name_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef_name' },
{ oid => '2506',
- descr => 'select statement of a view with pretty-print option',
+ descr => 'select statement of a view',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
prorettype => 'text', proargtypes => 'oid bool',
- prosrc => 'pg_get_viewdef_ext' },
+ proargnames => '{view,pretty}', proargdefaults => '{false}',
+ prosrc => 'pg_get_viewdef' },
{ oid => '3159',
descr => 'select statement of a view with pretty-printing and specified line wrapping',
proname => 'pg_get_viewdef', provolatile => 's', proparallel => 'r',
--
2.53.0
--AcCatzXgbvyipyEy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename=v8.1-0003-Handle-pg_get_indexdef-default-args-in-system_f.patch
^ permalink raw reply [nested|flat] 342+ messages in thread
* [PATCH v6] contrib/sslinfo: Add ssl_group_info
@ 2026-05-13 17:51 Dmitrii Dolgov <[email protected]>
0 siblings, 0 replies; 342+ messages in thread
From: Dmitrii Dolgov @ 2026-05-13 17:51 UTC (permalink / raw)
Add a new function to sslinfo ssl_group_info to show SSL groups,
including negotiated, supported and shared. It's useful for diagnostic
purposes, to identify what's being used and supported, e.g. which key
share is being negotiated. Few examples, for openssl 3.2.4:
select * from ssl_group_info();
type | name
------------+--------------------
negotiated | X25519MLKEM768
shared | X25519MLKEM768
shared | x25519
supported | X25519MLKEM768
supported | x25519
[...]
The implementation is inspired by ssl_print_groups from openssl.
Reviewed-by: Daniel Gustafsson <[email protected]>
Reviewed-by: Jacob Champion <[email protected]>
Reviewed-by: Cary Huang <[email protected]>
Reviewed-by: Zsolt Parragi <[email protected]>
---
configure | 36 +++++
configure.ac | 4 +
contrib/sslinfo/Makefile | 2 +-
contrib/sslinfo/meson.build | 1 +
contrib/sslinfo/sslinfo--1.2--1.3.sql | 10 ++
contrib/sslinfo/sslinfo.c | 192 +++++++++++++++++++++++++-
contrib/sslinfo/sslinfo.control | 2 +-
doc/src/sgml/sslinfo.sgml | 45 ++++++
meson.build | 5 +
src/include/pg_config.h.in | 11 ++
src/tools/pgindent/typedefs.list | 1 +
11 files changed, 306 insertions(+), 3 deletions(-)
create mode 100644 contrib/sslinfo/sslinfo--1.2--1.3.sql
diff --git a/configure b/configure
index f66c1054a7a..2a708df5afd 100755
--- a/configure
+++ b/configure
@@ -13189,6 +13189,42 @@ _ACEOF
fi
done
+ # Functions for groups support, some of them are real functions, some are
+ # just wrappers around SSL_ctrl.
+ for ac_func in SSL_group_to_name
+do :
+ ac_fn_c_check_func "$LINENO" "SSL_group_to_name" "ac_cv_func_SSL_group_to_name"
+if test "x$ac_cv_func_SSL_group_to_name" = xyes; then :
+ cat >>confdefs.h <<_ACEOF
+#define HAVE_SSL_GROUP_TO_NAME 1
+_ACEOF
+
+fi
+done
+
+ac_fn_c_check_decl "$LINENO" "SSL_get1_groups" "ac_cv_have_decl_SSL_get1_groups" "#include <openssl/ssl.h>
+"
+if test "x$ac_cv_have_decl_SSL_get1_groups" = xyes; then :
+ ac_have_decl=1
+else
+ ac_have_decl=0
+fi
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_SSL_GET1_GROUPS $ac_have_decl
+_ACEOF
+ac_fn_c_check_decl "$LINENO" "SSL_get_negotiated_group" "ac_cv_have_decl_SSL_get_negotiated_group" "#include <openssl/ssl.h>
+"
+if test "x$ac_cv_have_decl_SSL_get_negotiated_group" = xyes; then :
+ ac_have_decl=1
+else
+ ac_have_decl=0
+fi
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_SSL_GET_NEGOTIATED_GROUP $ac_have_decl
+_ACEOF
+
$as_echo "#define USE_OPENSSL 1" >>confdefs.h
diff --git a/configure.ac b/configure.ac
index 8d176bd3468..2641a17d317 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1444,6 +1444,10 @@ if test "$with_ssl" = openssl ; then
AC_CHECK_FUNCS([SSL_CTX_set_cert_cb])
# Function introduced in OpenSSL 1.1.1, not in LibreSSL.
AC_CHECK_FUNCS([X509_get_signature_info SSL_CTX_set_num_tickets SSL_CTX_set_keylog_callback SSL_CTX_set_client_hello_cb])
+ # Functions for groups support, some of them are real functions, some are
+ # just wrappers around SSL_ctrl.
+ AC_CHECK_FUNCS([SSL_group_to_name])
+ AC_CHECK_DECLS([SSL_get1_groups, SSL_get_negotiated_group], [], [], [#include <openssl/ssl.h>])
AC_DEFINE([USE_OPENSSL], 1, [Define to 1 to build with OpenSSL support. (--with-ssl=openssl)])
elif test "$with_ssl" != no ; then
AC_MSG_ERROR([--with-ssl must specify openssl])
diff --git a/contrib/sslinfo/Makefile b/contrib/sslinfo/Makefile
index 14305594e2d..d968ef2abfd 100644
--- a/contrib/sslinfo/Makefile
+++ b/contrib/sslinfo/Makefile
@@ -6,7 +6,7 @@ OBJS = \
sslinfo.o
EXTENSION = sslinfo
-DATA = sslinfo--1.2.sql sslinfo--1.1--1.2.sql sslinfo--1.0--1.1.sql
+DATA = sslinfo--1.2.sql sslinfo--1.2--1.3.sql sslinfo--1.1--1.2.sql sslinfo--1.0--1.1.sql
PGFILEDESC = "sslinfo - information about client SSL certificate"
ifdef USE_PGXS
diff --git a/contrib/sslinfo/meson.build b/contrib/sslinfo/meson.build
index 6e9cb96430a..27737562925 100644
--- a/contrib/sslinfo/meson.build
+++ b/contrib/sslinfo/meson.build
@@ -26,6 +26,7 @@ install_data(
'sslinfo--1.0--1.1.sql',
'sslinfo--1.1--1.2.sql',
'sslinfo--1.2.sql',
+ 'sslinfo--1.2--1.3.sql',
'sslinfo.control',
kwargs: contrib_data_args,
)
diff --git a/contrib/sslinfo/sslinfo--1.2--1.3.sql b/contrib/sslinfo/sslinfo--1.2--1.3.sql
new file mode 100644
index 00000000000..40fd0ea2b9c
--- /dev/null
+++ b/contrib/sslinfo/sslinfo--1.2--1.3.sql
@@ -0,0 +1,10 @@
+/* contrib/sslinfo/sslinfo--1.2--1.3.sql */
+
+-- complain if script is sourced in psql, rather than via ALTER EXTENSION
+\echo Use "ALTER EXTENSION sslinfo UPDATE TO '1.3'" to load this file. \quit
+
+CREATE FUNCTION
+ssl_group_info(OUT group_type text, OUT name text
+) RETURNS SETOF record
+AS 'MODULE_PATHNAME', 'ssl_group_info'
+LANGUAGE C STRICT PARALLEL RESTRICTED;
diff --git a/contrib/sslinfo/sslinfo.c b/contrib/sslinfo/sslinfo.c
index 2b9eb90b093..8807f50c908 100644
--- a/contrib/sslinfo/sslinfo.c
+++ b/contrib/sslinfo/sslinfo.c
@@ -19,6 +19,14 @@
#include "miscadmin.h"
#include "utils/builtins.h"
+#if HAVE_DECL_SSL_GET1_GROUPS && \
+ HAVE_DECL_SSL_GET_NEGOTIATED_GROUP && \
+ defined(HAVE_SSL_GROUP_TO_NAME) \
+
+#define HAVE_SSL_GROUPS
+
+#endif
+
PG_MODULE_MAGIC_EXT(
.name = "sslinfo",
.version = PG_VERSION
@@ -28,13 +36,28 @@ static Datum X509_NAME_field_to_text(X509_NAME *name, text *fieldName);
static Datum ASN1_STRING_to_text(ASN1_STRING *str);
/*
- * Function context for data persisting over repeated calls.
+ * Function context for data persisting over repeated calls of
+ * ssl_extension_info.
*/
typedef struct
{
TupleDesc tupdesc;
} SSLExtensionInfoContext;
+/*
+ * Function context for data persisting over repeated calls of
+ * ssl_group_info.
+ */
+typedef struct
+{
+ TupleDesc tupdesc;
+ int nshared;
+ int nsupported;
+
+ /* Supported groups have to be stored separately */
+ int *supported_groups;
+} SSLGroupInfoContext;
+
/*
* Indicates whether current session uses SSL
*
@@ -474,3 +497,170 @@ ssl_extension_info(PG_FUNCTION_ARGS)
/* All done */
SRF_RETURN_DONE(funcctx);
}
+
+/*
+ * Returns information about TLS groups.
+ *
+ * Returns setof record made of the following values:
+ * - type of the group: negotiated, shared, supported.
+ * - name of the group.
+ */
+PG_FUNCTION_INFO_V1(ssl_group_info);
+Datum
+ssl_group_info(PG_FUNCTION_ARGS)
+{
+#ifdef HAVE_SSL_GROUPS
+ /*
+ * If we lack SSL groups API, we still need to do SRF stuff. Thus the
+ * condition doesn't cover the whole function, but only parts of it. This
+ * particular one is only to avoid unused variable warning, in case if
+ * HAVE_SSL_GROUPS is false.
+ */
+ SSL *ssl = MyProcPort->ssl;
+#endif
+
+ FuncCallContext *funcctx;
+ int call_cntr = 0;
+ int max_calls = 0;
+ MemoryContext oldcontext;
+ SSLGroupInfoContext *fctx;
+
+ if (SRF_IS_FIRSTCALL())
+ {
+
+ TupleDesc tupdesc;
+
+ /* create a function context for cross-call persistence */
+ funcctx = SRF_FIRSTCALL_INIT();
+
+ /*
+ * Switch to memory context appropriate for multiple function calls
+ */
+ oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
+
+ /* Create a user function context for cross-call persistence */
+ fctx = palloc_object(SSLGroupInfoContext);
+
+ /* Construct tuple descriptor */
+ if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("function returning record called in context that cannot accept type record")));
+ fctx->tupdesc = BlessTupleDesc(tupdesc);
+
+ if (!MyProcPort->ssl_in_use)
+ {
+ /* fast track when no results */
+ MemoryContextSwitchTo(oldcontext);
+ SRF_RETURN_DONE(funcctx);
+ }
+
+#ifdef HAVE_SSL_GROUPS
+ if (ssl != NULL)
+ {
+ fctx->nsupported = SSL_get1_groups(ssl, NULL);
+ fctx->nshared = SSL_get_shared_group(ssl, -1);
+
+ fctx->supported_groups =
+ palloc(fctx->nsupported * sizeof(*fctx->supported_groups));
+ SSL_get1_groups(ssl, fctx->supported_groups);
+
+ /*
+ * Set max_calls as the number of supported groups plus the number
+ * of shared groups plus one negotiated group.
+ */
+ max_calls = fctx->nsupported + fctx->nshared + 1;
+ }
+
+ if (max_calls > 0)
+ {
+ /* got results, keep track of them */
+ funcctx->max_calls = max_calls;
+ funcctx->user_fctx = fctx;
+ }
+ else
+ {
+ /* fast track when no results */
+ MemoryContextSwitchTo(oldcontext);
+ SRF_RETURN_DONE(funcctx);
+ }
+#else
+ /* SSL groups API is not present, skip */
+ MemoryContextSwitchTo(oldcontext);
+ SRF_RETURN_DONE(funcctx);
+#endif
+
+ MemoryContextSwitchTo(oldcontext);
+ }
+
+ /* stuff done on every call of the function */
+ funcctx = SRF_PERCALL_SETUP();
+
+ /*
+ * Initialize per-call variables.
+ */
+ call_cntr = funcctx->call_cntr;
+ max_calls = funcctx->max_calls;
+ fctx = funcctx->user_fctx;
+
+ /* do while there are more left to send */
+ if (call_cntr < max_calls)
+ {
+#ifdef HAVE_SSL_GROUPS
+ Datum values[2];
+ bool nulls[2];
+ HeapTuple tuple;
+ Datum result,
+ group_type;
+ int nid;
+ const char *group_name;
+
+ /* Send the negotiated group first */
+ if (call_cntr == 0)
+ {
+ nid = SSL_get_negotiated_group(ssl);
+ group_type = CStringGetTextDatum("negotiated");
+ }
+ /* Then the shared groups */
+ else if (call_cntr < fctx->nshared + 1)
+ {
+ nid = SSL_get_shared_group(ssl, call_cntr - 1);
+ group_type = CStringGetTextDatum("shared");
+ }
+ /* And finally the supported groups */
+ else if (call_cntr < fctx->nsupported + fctx->nshared + 1)
+ {
+ nid = fctx->supported_groups[call_cntr - fctx->nshared - 1];
+ group_type = CStringGetTextDatum("supported");
+ }
+ else
+ SRF_RETURN_DONE(funcctx);
+
+ /*
+ * SSL_group_to_name can return NULL in case of an error, e.g. when no
+ * such name was registered for some reason.
+ */
+ group_name = SSL_group_to_name(ssl, nid);
+ if (group_name == NULL)
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("unknown OpenSSL group at position %d",
+ call_cntr)));
+
+ values[0] = group_type;
+ nulls[0] = false;
+
+ values[1] = CStringGetTextDatum(group_name);
+ nulls[1] = false;
+
+ /* Build tuple */
+ tuple = heap_form_tuple(fctx->tupdesc, values, nulls);
+ result = HeapTupleGetDatum(tuple);
+
+ SRF_RETURN_NEXT(funcctx, result);
+#endif
+ }
+
+ /* All done */
+ SRF_RETURN_DONE(funcctx);
+}
diff --git a/contrib/sslinfo/sslinfo.control b/contrib/sslinfo/sslinfo.control
index c7754f924cf..b53e95b7da8 100644
--- a/contrib/sslinfo/sslinfo.control
+++ b/contrib/sslinfo/sslinfo.control
@@ -1,5 +1,5 @@
# sslinfo extension
comment = 'information about SSL certificates'
-default_version = '1.2'
+default_version = '1.3'
module_pathname = '$libdir/sslinfo'
relocatable = true
diff --git a/doc/src/sgml/sslinfo.sgml b/doc/src/sgml/sslinfo.sgml
index 85d49f66537..34fc187e4e4 100644
--- a/doc/src/sgml/sslinfo.sgml
+++ b/doc/src/sgml/sslinfo.sgml
@@ -240,6 +240,51 @@ emailAddress
</para>
</listitem>
</varlistentry>
+
+ <varlistentry>
+ <term>
+ <function>ssl_group_info() returns setof record</function>
+ <indexterm>
+ <primary>ssl_group_info</primary>
+ </indexterm>
+ </term>
+ <listitem>
+ <para>
+ Provide information about TLS groups: group type and group name.
+ The group type value could be one of the following:
+
+ <variablelist>
+ <varlistentry id="ssl-group-info-negotiated">
+ <term><literal>negotiated</literal></term>
+ <listitem>
+ <para>
+ The group used for the handshake key exchange process.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry id="ssl-group-info-shared">
+ <term><literal>shared</literal></term>
+ <listitem>
+ <para>
+ List of named groups shared with the server side.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry id="ssl-group-info-supported">
+ <term><literal>supported</literal></term>
+ <listitem>
+ <para>
+ list of named groups supported by the client for key exchange in the
+ form of "supported_groups" extension.
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </para>
+ </listitem>
+ </varlistentry>
</variablelist>
</sect2>
diff --git a/meson.build b/meson.build
index 20b887f1a1b..90e99705656 100644
--- a/meson.build
+++ b/meson.build
@@ -1677,6 +1677,9 @@ if sslopt in ['auto', 'openssl']
['SSL_CTX_set_num_tickets'],
['SSL_CTX_set_keylog_callback'],
['SSL_CTX_set_client_hello_cb'],
+
+ # Function for groups support.
+ ['SSL_group_to_name'],
]
are_openssl_funcs_complete = true
@@ -2901,6 +2904,8 @@ decl_checks = [
['strlcpy', 'string.h'],
['strsep', 'string.h'],
['timingsafe_bcmp', 'string.h'],
+ ['SSL_get1_groups', 'openssl/ssl.h'],
+ ['SSL_get_negotiated_group', 'openssl/ssl.h'],
]
# Need to check for function declarations for these functions, because
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index 4f8113c144b..67090821722 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -101,6 +101,14 @@
don't. */
#undef HAVE_DECL_PWRITEV
+/* Define to 1 if you have the declaration of `SSL_get1_groups', and to 0 if
+ you don't. */
+#undef HAVE_DECL_SSL_GET1_GROUPS
+
+/* Define to 1 if you have the declaration of `SSL_get_negotiated_group', and
+ to 0 if you don't. */
+#undef HAVE_DECL_SSL_GET_NEGOTIATED_GROUP
+
/* Define to 1 if you have the declaration of `strchrnul', and to 0 if you
don't. */
#undef HAVE_DECL_STRCHRNUL
@@ -384,6 +392,9 @@
/* Define to 1 if you have the `SSL_CTX_set_num_tickets' function. */
#undef HAVE_SSL_CTX_SET_NUM_TICKETS
+/* Define to 1 if you have the `SSL_group_to_name' function. */
+#undef HAVE_SSL_GROUP_TO_NAME
+
/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index cbd9e10fc1d..cb8b4ea306e 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -2777,6 +2777,7 @@ SQLValueFunction
SQLValueFunctionOp
SSL
SSLExtensionInfoContext
+SSLGroupInfoContext
SSL_CTX
STARTUPINFO
STRLEN
base-commit: 3bf63730cb041a834c618082ba3d5e8bf96a31a5
--
2.52.0
--vt4heavyb5tqbgln--
^ permalink raw reply [nested|flat] 342+ messages in thread
end of thread, other threads:[~2026-05-13 17:51 UTC | newest]
Thread overview: 342+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-04-04 22:13 [PATCH v20220916 07/13] DISCARD VARIABLES command [email protected] <[email protected]>
2022-04-04 22:13 [PATCH v20220922 07/13] DISCARD VARIABLES command [email protected] <[email protected]>
2022-04-04 22:13 [PATCH 05/11] DISCARD VARIABLES command [email protected] <[email protected]>
2022-04-04 22:13 [PATCH 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]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 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 v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 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 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 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 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 v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 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 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 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 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 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 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 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 v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 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 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 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 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 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 v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 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 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 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 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.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 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 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 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 v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 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 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 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 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 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 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 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 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 v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 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 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 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 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 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 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 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 v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 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 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 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 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 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 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 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 v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 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 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 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 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 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 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 v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 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 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 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 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 v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 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 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 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 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 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 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 v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2026-05-13 17:51 [PATCH v6] contrib/sslinfo: Add ssl_group_info Dmitrii Dolgov <[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