($INBOX_DIR/description missing)
help / color / mirror / Atom feed[PATCH 1/3] Add operator <->(box, point)
4308+ messages / 6 participants
[nested] [flat]
* [PATCH 1/3] Add operator <->(box, point)
@ 2019-03-07 17:22 Nikita Glukhov <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Nikita Glukhov @ 2019-03-07 17:22 UTC (permalink / raw)
---
src/backend/utils/adt/geo_ops.c | 12 +++++
src/include/catalog/pg_operator.dat | 5 +-
src/include/catalog/pg_proc.dat | 3 ++
src/test/regress/expected/geometry.out | 96 +++++++++++++++++-----------------
src/test/regress/sql/geometry.sql | 2 +-
5 files changed, 68 insertions(+), 50 deletions(-)
diff --git a/src/backend/utils/adt/geo_ops.c b/src/backend/utils/adt/geo_ops.c
index 373784f..d8ecfe3 100644
--- a/src/backend/utils/adt/geo_ops.c
+++ b/src/backend/utils/adt/geo_ops.c
@@ -2419,6 +2419,18 @@ dist_pb(PG_FUNCTION_ARGS)
}
/*
+ * Distance from a box to a point
+ */
+Datum
+dist_bp(PG_FUNCTION_ARGS)
+{
+ BOX *box = PG_GETARG_BOX_P(0);
+ Point *pt = PG_GETARG_POINT_P(1);
+
+ PG_RETURN_FLOAT8(box_closept_point(NULL, box, pt));
+}
+
+/*
* Distance from a lseg to a line
*/
Datum
diff --git a/src/include/catalog/pg_operator.dat b/src/include/catalog/pg_operator.dat
index bacafa5..ae5ed1e 100644
--- a/src/include/catalog/pg_operator.dat
+++ b/src/include/catalog/pg_operator.dat
@@ -666,7 +666,10 @@
oprresult => 'float8', oprcode => 'dist_ps' },
{ oid => '615', descr => 'distance between',
oprname => '<->', oprleft => 'point', oprright => 'box',
- oprresult => 'float8', oprcode => 'dist_pb' },
+ oprresult => 'float8', oprcom => '<->(box,point)', oprcode => 'dist_pb' },
+{ oid => '606', descr => 'distance between',
+ oprname => '<->', oprleft => 'box', oprright => 'point',
+ oprresult => 'float8', oprcom => '<->(point,box)', oprcode => 'dist_bp' },
{ oid => '616', descr => 'distance between',
oprname => '<->', oprleft => 'lseg', oprright => 'line',
oprresult => 'float8', oprcode => 'dist_sl' },
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 8733524..54327bf 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -1065,6 +1065,9 @@
{ oid => '364',
proname => 'dist_pb', prorettype => 'float8', proargtypes => 'point box',
prosrc => 'dist_pb' },
+{ oid => '357',
+ proname => 'dist_bp', prorettype => 'float8', proargtypes => 'box point',
+ prosrc => 'dist_bp' },
{ oid => '365',
proname => 'dist_sb', prorettype => 'float8', proargtypes => 'lseg box',
prosrc => 'dist_sb' },
diff --git a/src/test/regress/expected/geometry.out b/src/test/regress/expected/geometry.out
index 055d32c..6be3a39 100644
--- a/src/test/regress/expected/geometry.out
+++ b/src/test/regress/expected/geometry.out
@@ -602,54 +602,54 @@ SELECT p.f1, l.s, p.f1 <-> l.s FROM POINT_TBL p, LSEG_TBL l;
(72 rows)
-- Distance to box
-SELECT p.f1, b.f1, p.f1 <-> b.f1 FROM POINT_TBL p, BOX_TBL b;
- f1 | f1 | ?column?
--------------------+---------------------+--------------------
- (0,0) | (2,2),(0,0) | 0
- (0,0) | (3,3),(1,1) | 1.41421356237
- (0,0) | (-2,2),(-8,-10) | 2
- (0,0) | (2.5,3.5),(2.5,2.5) | 3.53553390593
- (0,0) | (3,3),(3,3) | 4.24264068712
- (-10,0) | (2,2),(0,0) | 10
- (-10,0) | (3,3),(1,1) | 11.0453610172
- (-10,0) | (-2,2),(-8,-10) | 2
- (-10,0) | (2.5,3.5),(2.5,2.5) | 12.747548784
- (-10,0) | (3,3),(3,3) | 13.3416640641
- (-3,4) | (2,2),(0,0) | 3.60555127546
- (-3,4) | (3,3),(1,1) | 4.12310562562
- (-3,4) | (-2,2),(-8,-10) | 2
- (-3,4) | (2.5,3.5),(2.5,2.5) | 5.52268050859
- (-3,4) | (3,3),(3,3) | 6.0827625303
- (5.1,34.5) | (2,2),(0,0) | 32.6475113906
- (5.1,34.5) | (3,3),(1,1) | 31.5699223946
- (5.1,34.5) | (-2,2),(-8,-10) | 33.2664996656
- (5.1,34.5) | (2.5,3.5),(2.5,2.5) | 31.108841187
- (5.1,34.5) | (3,3),(3,3) | 31.5699223946
- (-5,-12) | (2,2),(0,0) | 13
- (-5,-12) | (3,3),(1,1) | 14.3178210633
- (-5,-12) | (-2,2),(-8,-10) | 2
- (-5,-12) | (2.5,3.5),(2.5,2.5) | 16.3248277173
- (-5,-12) | (3,3),(3,3) | 17
- (1e-300,-1e-300) | (2,2),(0,0) | 1.41421356237e-300
- (1e-300,-1e-300) | (3,3),(1,1) | 1.41421356237
- (1e-300,-1e-300) | (-2,2),(-8,-10) | 2
- (1e-300,-1e-300) | (2.5,3.5),(2.5,2.5) | 3.53553390593
- (1e-300,-1e-300) | (3,3),(3,3) | 4.24264068712
- (1e+300,Infinity) | (2,2),(0,0) | Infinity
- (1e+300,Infinity) | (3,3),(1,1) | Infinity
- (1e+300,Infinity) | (-2,2),(-8,-10) | Infinity
- (1e+300,Infinity) | (2.5,3.5),(2.5,2.5) | Infinity
- (1e+300,Infinity) | (3,3),(3,3) | Infinity
- (NaN,NaN) | (2,2),(0,0) | NaN
- (NaN,NaN) | (3,3),(1,1) | NaN
- (NaN,NaN) | (-2,2),(-8,-10) | NaN
- (NaN,NaN) | (2.5,3.5),(2.5,2.5) | NaN
- (NaN,NaN) | (3,3),(3,3) | NaN
- (10,10) | (2,2),(0,0) | 11.313708499
- (10,10) | (3,3),(1,1) | 9.89949493661
- (10,10) | (-2,2),(-8,-10) | 14.4222051019
- (10,10) | (2.5,3.5),(2.5,2.5) | 9.92471662064
- (10,10) | (3,3),(3,3) | 9.89949493661
+SELECT p.f1, b.f1, p.f1 <-> b.f1 AS pt_box_dist, b.f1 <-> p.f1 AS box_pt_dist FROM POINT_TBL p, BOX_TBL b;
+ f1 | f1 | pt_box_dist | box_pt_dist
+-------------------+---------------------+--------------------+--------------------
+ (0,0) | (2,2),(0,0) | 0 | 0
+ (0,0) | (3,3),(1,1) | 1.41421356237 | 1.41421356237
+ (0,0) | (-2,2),(-8,-10) | 2 | 2
+ (0,0) | (2.5,3.5),(2.5,2.5) | 3.53553390593 | 3.53553390593
+ (0,0) | (3,3),(3,3) | 4.24264068712 | 4.24264068712
+ (-10,0) | (2,2),(0,0) | 10 | 10
+ (-10,0) | (3,3),(1,1) | 11.0453610172 | 11.0453610172
+ (-10,0) | (-2,2),(-8,-10) | 2 | 2
+ (-10,0) | (2.5,3.5),(2.5,2.5) | 12.747548784 | 12.747548784
+ (-10,0) | (3,3),(3,3) | 13.3416640641 | 13.3416640641
+ (-3,4) | (2,2),(0,0) | 3.60555127546 | 3.60555127546
+ (-3,4) | (3,3),(1,1) | 4.12310562562 | 4.12310562562
+ (-3,4) | (-2,2),(-8,-10) | 2 | 2
+ (-3,4) | (2.5,3.5),(2.5,2.5) | 5.52268050859 | 5.52268050859
+ (-3,4) | (3,3),(3,3) | 6.0827625303 | 6.0827625303
+ (5.1,34.5) | (2,2),(0,0) | 32.6475113906 | 32.6475113906
+ (5.1,34.5) | (3,3),(1,1) | 31.5699223946 | 31.5699223946
+ (5.1,34.5) | (-2,2),(-8,-10) | 33.2664996656 | 33.2664996656
+ (5.1,34.5) | (2.5,3.5),(2.5,2.5) | 31.108841187 | 31.108841187
+ (5.1,34.5) | (3,3),(3,3) | 31.5699223946 | 31.5699223946
+ (-5,-12) | (2,2),(0,0) | 13 | 13
+ (-5,-12) | (3,3),(1,1) | 14.3178210633 | 14.3178210633
+ (-5,-12) | (-2,2),(-8,-10) | 2 | 2
+ (-5,-12) | (2.5,3.5),(2.5,2.5) | 16.3248277173 | 16.3248277173
+ (-5,-12) | (3,3),(3,3) | 17 | 17
+ (1e-300,-1e-300) | (2,2),(0,0) | 1.41421356237e-300 | 1.41421356237e-300
+ (1e-300,-1e-300) | (3,3),(1,1) | 1.41421356237 | 1.41421356237
+ (1e-300,-1e-300) | (-2,2),(-8,-10) | 2 | 2
+ (1e-300,-1e-300) | (2.5,3.5),(2.5,2.5) | 3.53553390593 | 3.53553390593
+ (1e-300,-1e-300) | (3,3),(3,3) | 4.24264068712 | 4.24264068712
+ (1e+300,Infinity) | (2,2),(0,0) | Infinity | Infinity
+ (1e+300,Infinity) | (3,3),(1,1) | Infinity | Infinity
+ (1e+300,Infinity) | (-2,2),(-8,-10) | Infinity | Infinity
+ (1e+300,Infinity) | (2.5,3.5),(2.5,2.5) | Infinity | Infinity
+ (1e+300,Infinity) | (3,3),(3,3) | Infinity | Infinity
+ (NaN,NaN) | (2,2),(0,0) | NaN | NaN
+ (NaN,NaN) | (3,3),(1,1) | NaN | NaN
+ (NaN,NaN) | (-2,2),(-8,-10) | NaN | NaN
+ (NaN,NaN) | (2.5,3.5),(2.5,2.5) | NaN | NaN
+ (NaN,NaN) | (3,3),(3,3) | NaN | NaN
+ (10,10) | (2,2),(0,0) | 11.313708499 | 11.313708499
+ (10,10) | (3,3),(1,1) | 9.89949493661 | 9.89949493661
+ (10,10) | (-2,2),(-8,-10) | 14.4222051019 | 14.4222051019
+ (10,10) | (2.5,3.5),(2.5,2.5) | 9.92471662064 | 9.92471662064
+ (10,10) | (3,3),(3,3) | 9.89949493661 | 9.89949493661
(45 rows)
-- Distance to path
diff --git a/src/test/regress/sql/geometry.sql b/src/test/regress/sql/geometry.sql
index ce98b3e..8fd02cf 100644
--- a/src/test/regress/sql/geometry.sql
+++ b/src/test/regress/sql/geometry.sql
@@ -77,7 +77,7 @@ SELECT p.f1, l.s, p.f1 <-> l.s FROM POINT_TBL p, LINE_TBL l;
SELECT p.f1, l.s, p.f1 <-> l.s FROM POINT_TBL p, LSEG_TBL l;
-- Distance to box
-SELECT p.f1, b.f1, p.f1 <-> b.f1 FROM POINT_TBL p, BOX_TBL b;
+SELECT p.f1, b.f1, p.f1 <-> b.f1 AS pt_box_dist, b.f1 <-> p.f1 AS box_pt_dist FROM POINT_TBL p, BOX_TBL b;
-- Distance to path
SELECT p.f1, p1.f1, p.f1 <-> p1.f1 FROM POINT_TBL p, PATH_TBL p1;
--
2.7.4
--------------07EE9595454874974EAD75E7
Content-Type: text/x-patch;
name="0002-Add-operator-box-point-to-GiST-box_ops-v02.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="0002-Add-operator-box-point-to-GiST-box_ops-v02.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH 1/3] Add operator <->(box, point)
@ 2019-03-07 17:22 Nikita Glukhov <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Nikita Glukhov @ 2019-03-07 17:22 UTC (permalink / raw)
---
src/backend/utils/adt/geo_ops.c | 12 +++++
src/include/catalog/pg_operator.dat | 5 +-
src/include/catalog/pg_proc.dat | 3 ++
src/test/regress/expected/geometry.out | 96 +++++++++++++++++-----------------
src/test/regress/sql/geometry.sql | 2 +-
5 files changed, 68 insertions(+), 50 deletions(-)
diff --git a/src/backend/utils/adt/geo_ops.c b/src/backend/utils/adt/geo_ops.c
index 28e85e3..a8f9111 100644
--- a/src/backend/utils/adt/geo_ops.c
+++ b/src/backend/utils/adt/geo_ops.c
@@ -2419,6 +2419,18 @@ dist_pb(PG_FUNCTION_ARGS)
}
/*
+ * Distance from a box to a point
+ */
+Datum
+dist_bp(PG_FUNCTION_ARGS)
+{
+ BOX *box = PG_GETARG_BOX_P(0);
+ Point *pt = PG_GETARG_POINT_P(1);
+
+ PG_RETURN_FLOAT8(box_closept_point(NULL, box, pt));
+}
+
+/*
* Distance from a lseg to a line
*/
Datum
diff --git a/src/include/catalog/pg_operator.dat b/src/include/catalog/pg_operator.dat
index 06aec07..ebace5a 100644
--- a/src/include/catalog/pg_operator.dat
+++ b/src/include/catalog/pg_operator.dat
@@ -666,7 +666,10 @@
oprresult => 'float8', oprcode => 'dist_ps' },
{ oid => '615', descr => 'distance between',
oprname => '<->', oprleft => 'point', oprright => 'box',
- oprresult => 'float8', oprcode => 'dist_pb' },
+ oprresult => 'float8', oprcom => '<->(box,point)', oprcode => 'dist_pb' },
+{ oid => '606', descr => 'distance between',
+ oprname => '<->', oprleft => 'box', oprright => 'point',
+ oprresult => 'float8', oprcom => '<->(point,box)', oprcode => 'dist_bp' },
{ oid => '616', descr => 'distance between',
oprname => '<->', oprleft => 'lseg', oprright => 'line',
oprresult => 'float8', oprcode => 'dist_sl' },
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 562c540..3800150 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -1062,6 +1062,9 @@
{ oid => '364',
proname => 'dist_pb', prorettype => 'float8', proargtypes => 'point box',
prosrc => 'dist_pb' },
+{ oid => '357',
+ proname => 'dist_bp', prorettype => 'float8', proargtypes => 'box point',
+ prosrc => 'dist_bp' },
{ oid => '365',
proname => 'dist_sb', prorettype => 'float8', proargtypes => 'lseg box',
prosrc => 'dist_sb' },
diff --git a/src/test/regress/expected/geometry.out b/src/test/regress/expected/geometry.out
index 055d32c..5efe80a 100644
--- a/src/test/regress/expected/geometry.out
+++ b/src/test/regress/expected/geometry.out
@@ -602,54 +602,54 @@ SELECT p.f1, l.s, p.f1 <-> l.s FROM POINT_TBL p, LSEG_TBL l;
(72 rows)
-- Distance to box
-SELECT p.f1, b.f1, p.f1 <-> b.f1 FROM POINT_TBL p, BOX_TBL b;
- f1 | f1 | ?column?
--------------------+---------------------+--------------------
- (0,0) | (2,2),(0,0) | 0
- (0,0) | (3,3),(1,1) | 1.41421356237
- (0,0) | (-2,2),(-8,-10) | 2
- (0,0) | (2.5,3.5),(2.5,2.5) | 3.53553390593
- (0,0) | (3,3),(3,3) | 4.24264068712
- (-10,0) | (2,2),(0,0) | 10
- (-10,0) | (3,3),(1,1) | 11.0453610172
- (-10,0) | (-2,2),(-8,-10) | 2
- (-10,0) | (2.5,3.5),(2.5,2.5) | 12.747548784
- (-10,0) | (3,3),(3,3) | 13.3416640641
- (-3,4) | (2,2),(0,0) | 3.60555127546
- (-3,4) | (3,3),(1,1) | 4.12310562562
- (-3,4) | (-2,2),(-8,-10) | 2
- (-3,4) | (2.5,3.5),(2.5,2.5) | 5.52268050859
- (-3,4) | (3,3),(3,3) | 6.0827625303
- (5.1,34.5) | (2,2),(0,0) | 32.6475113906
- (5.1,34.5) | (3,3),(1,1) | 31.5699223946
- (5.1,34.5) | (-2,2),(-8,-10) | 33.2664996656
- (5.1,34.5) | (2.5,3.5),(2.5,2.5) | 31.108841187
- (5.1,34.5) | (3,3),(3,3) | 31.5699223946
- (-5,-12) | (2,2),(0,0) | 13
- (-5,-12) | (3,3),(1,1) | 14.3178210633
- (-5,-12) | (-2,2),(-8,-10) | 2
- (-5,-12) | (2.5,3.5),(2.5,2.5) | 16.3248277173
- (-5,-12) | (3,3),(3,3) | 17
- (1e-300,-1e-300) | (2,2),(0,0) | 1.41421356237e-300
- (1e-300,-1e-300) | (3,3),(1,1) | 1.41421356237
- (1e-300,-1e-300) | (-2,2),(-8,-10) | 2
- (1e-300,-1e-300) | (2.5,3.5),(2.5,2.5) | 3.53553390593
- (1e-300,-1e-300) | (3,3),(3,3) | 4.24264068712
- (1e+300,Infinity) | (2,2),(0,0) | Infinity
- (1e+300,Infinity) | (3,3),(1,1) | Infinity
- (1e+300,Infinity) | (-2,2),(-8,-10) | Infinity
- (1e+300,Infinity) | (2.5,3.5),(2.5,2.5) | Infinity
- (1e+300,Infinity) | (3,3),(3,3) | Infinity
- (NaN,NaN) | (2,2),(0,0) | NaN
- (NaN,NaN) | (3,3),(1,1) | NaN
- (NaN,NaN) | (-2,2),(-8,-10) | NaN
- (NaN,NaN) | (2.5,3.5),(2.5,2.5) | NaN
- (NaN,NaN) | (3,3),(3,3) | NaN
- (10,10) | (2,2),(0,0) | 11.313708499
- (10,10) | (3,3),(1,1) | 9.89949493661
- (10,10) | (-2,2),(-8,-10) | 14.4222051019
- (10,10) | (2.5,3.5),(2.5,2.5) | 9.92471662064
- (10,10) | (3,3),(3,3) | 9.89949493661
+SELECT p.f1, b.f1, p.f1 <-> b.f1, b.f1 <-> p.f1 FROM POINT_TBL p, BOX_TBL b;
+ f1 | f1 | ?column? | ?column?
+-------------------+---------------------+--------------------+--------------------
+ (0,0) | (2,2),(0,0) | 0 | 0
+ (0,0) | (3,3),(1,1) | 1.41421356237 | 1.41421356237
+ (0,0) | (-2,2),(-8,-10) | 2 | 2
+ (0,0) | (2.5,3.5),(2.5,2.5) | 3.53553390593 | 3.53553390593
+ (0,0) | (3,3),(3,3) | 4.24264068712 | 4.24264068712
+ (-10,0) | (2,2),(0,0) | 10 | 10
+ (-10,0) | (3,3),(1,1) | 11.0453610172 | 11.0453610172
+ (-10,0) | (-2,2),(-8,-10) | 2 | 2
+ (-10,0) | (2.5,3.5),(2.5,2.5) | 12.747548784 | 12.747548784
+ (-10,0) | (3,3),(3,3) | 13.3416640641 | 13.3416640641
+ (-3,4) | (2,2),(0,0) | 3.60555127546 | 3.60555127546
+ (-3,4) | (3,3),(1,1) | 4.12310562562 | 4.12310562562
+ (-3,4) | (-2,2),(-8,-10) | 2 | 2
+ (-3,4) | (2.5,3.5),(2.5,2.5) | 5.52268050859 | 5.52268050859
+ (-3,4) | (3,3),(3,3) | 6.0827625303 | 6.0827625303
+ (5.1,34.5) | (2,2),(0,0) | 32.6475113906 | 32.6475113906
+ (5.1,34.5) | (3,3),(1,1) | 31.5699223946 | 31.5699223946
+ (5.1,34.5) | (-2,2),(-8,-10) | 33.2664996656 | 33.2664996656
+ (5.1,34.5) | (2.5,3.5),(2.5,2.5) | 31.108841187 | 31.108841187
+ (5.1,34.5) | (3,3),(3,3) | 31.5699223946 | 31.5699223946
+ (-5,-12) | (2,2),(0,0) | 13 | 13
+ (-5,-12) | (3,3),(1,1) | 14.3178210633 | 14.3178210633
+ (-5,-12) | (-2,2),(-8,-10) | 2 | 2
+ (-5,-12) | (2.5,3.5),(2.5,2.5) | 16.3248277173 | 16.3248277173
+ (-5,-12) | (3,3),(3,3) | 17 | 17
+ (1e-300,-1e-300) | (2,2),(0,0) | 1.41421356237e-300 | 1.41421356237e-300
+ (1e-300,-1e-300) | (3,3),(1,1) | 1.41421356237 | 1.41421356237
+ (1e-300,-1e-300) | (-2,2),(-8,-10) | 2 | 2
+ (1e-300,-1e-300) | (2.5,3.5),(2.5,2.5) | 3.53553390593 | 3.53553390593
+ (1e-300,-1e-300) | (3,3),(3,3) | 4.24264068712 | 4.24264068712
+ (1e+300,Infinity) | (2,2),(0,0) | Infinity | Infinity
+ (1e+300,Infinity) | (3,3),(1,1) | Infinity | Infinity
+ (1e+300,Infinity) | (-2,2),(-8,-10) | Infinity | Infinity
+ (1e+300,Infinity) | (2.5,3.5),(2.5,2.5) | Infinity | Infinity
+ (1e+300,Infinity) | (3,3),(3,3) | Infinity | Infinity
+ (NaN,NaN) | (2,2),(0,0) | NaN | NaN
+ (NaN,NaN) | (3,3),(1,1) | NaN | NaN
+ (NaN,NaN) | (-2,2),(-8,-10) | NaN | NaN
+ (NaN,NaN) | (2.5,3.5),(2.5,2.5) | NaN | NaN
+ (NaN,NaN) | (3,3),(3,3) | NaN | NaN
+ (10,10) | (2,2),(0,0) | 11.313708499 | 11.313708499
+ (10,10) | (3,3),(1,1) | 9.89949493661 | 9.89949493661
+ (10,10) | (-2,2),(-8,-10) | 14.4222051019 | 14.4222051019
+ (10,10) | (2.5,3.5),(2.5,2.5) | 9.92471662064 | 9.92471662064
+ (10,10) | (3,3),(3,3) | 9.89949493661 | 9.89949493661
(45 rows)
-- Distance to path
diff --git a/src/test/regress/sql/geometry.sql b/src/test/regress/sql/geometry.sql
index ce98b3e..9fbd123 100644
--- a/src/test/regress/sql/geometry.sql
+++ b/src/test/regress/sql/geometry.sql
@@ -77,7 +77,7 @@ SELECT p.f1, l.s, p.f1 <-> l.s FROM POINT_TBL p, LINE_TBL l;
SELECT p.f1, l.s, p.f1 <-> l.s FROM POINT_TBL p, LSEG_TBL l;
-- Distance to box
-SELECT p.f1, b.f1, p.f1 <-> b.f1 FROM POINT_TBL p, BOX_TBL b;
+SELECT p.f1, b.f1, p.f1 <-> b.f1, b.f1 <-> p.f1 FROM POINT_TBL p, BOX_TBL b;
-- Distance to path
SELECT p.f1, p1.f1, p.f1 <-> p1.f1 FROM POINT_TBL p, PATH_TBL p1;
--
2.7.4
--------------B01ADF66983FA504E371CA13
Content-Type: text/x-patch;
name="0002-Add-box-point-distance-operator-to-GiST-box_ops-v01.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename*0="0002-Add-box-point-distance-operator-to-GiST-box_ops-v01.pat";
filename*1="ch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v1 3/7] Row pattern recognition patch (planner).
@ 2023-06-25 11:48 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-06-25 11:48 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 13 ++++++++++---
src/include/nodes/plannodes.h | 9 +++++++++
2 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 4bb38160b3..5ac65248a2 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -287,8 +287,8 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ List *runCondition, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2684,6 +2684,9 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6581,7 +6584,8 @@ make_windowagg(List *tlist, Index winref,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ List *runCondition, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6607,6 +6611,9 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1b787fe031..eb511176ac 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,15 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern Recognition PATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern Recognition DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Sun_Jun_25_21_05_09_2023_126)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v1-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v1 3/7] Row pattern recognition patch (planner).
@ 2023-06-25 11:48 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-06-25 11:48 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 13 ++++++++++---
src/include/nodes/plannodes.h | 9 +++++++++
2 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 4bb38160b3..5ac65248a2 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -287,8 +287,8 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ List *runCondition, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2684,6 +2684,9 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6581,7 +6584,8 @@ make_windowagg(List *tlist, Index winref,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ List *runCondition, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6607,6 +6611,9 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1b787fe031..eb511176ac 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,15 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern Recognition PATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern Recognition DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Sun_Jun_25_21_05_09_2023_126)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v1-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v1 3/7] Row pattern recognition patch (planner).
@ 2023-06-25 11:48 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-06-25 11:48 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 13 ++++++++++---
src/include/nodes/plannodes.h | 9 +++++++++
2 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 4bb38160b3..5ac65248a2 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -287,8 +287,8 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ List *runCondition, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2684,6 +2684,9 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6581,7 +6584,8 @@ make_windowagg(List *tlist, Index winref,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ List *runCondition, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6607,6 +6611,9 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1b787fe031..eb511176ac 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,15 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern Recognition PATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern Recognition DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Sun_Jun_25_21_05_09_2023_126)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v1-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v1 3/7] Row pattern recognition patch (planner).
@ 2023-06-25 11:48 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-06-25 11:48 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 13 ++++++++++---
src/include/nodes/plannodes.h | 9 +++++++++
2 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 4bb38160b3..5ac65248a2 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -287,8 +287,8 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ List *runCondition, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2684,6 +2684,9 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6581,7 +6584,8 @@ make_windowagg(List *tlist, Index winref,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ List *runCondition, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6607,6 +6611,9 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1b787fe031..eb511176ac 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,15 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern Recognition PATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern Recognition DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Sun_Jun_25_21_05_09_2023_126)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v1-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v1 3/7] Row pattern recognition patch (planner).
@ 2023-06-25 11:48 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-06-25 11:48 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 13 ++++++++++---
src/include/nodes/plannodes.h | 9 +++++++++
2 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 4bb38160b3..5ac65248a2 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -287,8 +287,8 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ List *runCondition, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2684,6 +2684,9 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6581,7 +6584,8 @@ make_windowagg(List *tlist, Index winref,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ List *runCondition, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6607,6 +6611,9 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1b787fe031..eb511176ac 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,15 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern Recognition PATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern Recognition DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Sun_Jun_25_21_05_09_2023_126)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v1-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v2 3/7] Row pattern recognition patch (planner).
@ 2023-06-26 08:05 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-06-26 08:05 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 19 ++++++++++++++-----
src/include/nodes/plannodes.h | 12 ++++++++++++
2 files changed, 26 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 4bb38160b3..c10ac65a4c 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,9 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2684,6 +2684,10 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6580,8 +6584,9 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6607,6 +6612,10 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1b787fe031..cc942b9c12 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,18 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern Recognition PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern Recognition PATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern Recognition DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Mon_Jun_26_17_45_07_2023_724)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v2-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v2 3/7] Row pattern recognition patch (planner).
@ 2023-06-26 08:05 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-06-26 08:05 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 19 ++++++++++++++-----
src/include/nodes/plannodes.h | 12 ++++++++++++
2 files changed, 26 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 4bb38160b3..c10ac65a4c 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,9 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2684,6 +2684,10 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6580,8 +6584,9 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6607,6 +6612,10 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1b787fe031..cc942b9c12 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,18 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern Recognition PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern Recognition PATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern Recognition DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Mon_Jun_26_17_45_07_2023_724)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v2-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v2 3/7] Row pattern recognition patch (planner).
@ 2023-06-26 08:05 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-06-26 08:05 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 19 ++++++++++++++-----
src/include/nodes/plannodes.h | 12 ++++++++++++
2 files changed, 26 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 4bb38160b3..c10ac65a4c 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,9 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2684,6 +2684,10 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6580,8 +6584,9 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6607,6 +6612,10 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1b787fe031..cc942b9c12 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,18 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern Recognition PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern Recognition PATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern Recognition DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Mon_Jun_26_17_45_07_2023_724)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v2-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v2 3/7] Row pattern recognition patch (planner).
@ 2023-06-26 08:05 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-06-26 08:05 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 19 ++++++++++++++-----
src/include/nodes/plannodes.h | 12 ++++++++++++
2 files changed, 26 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 4bb38160b3..c10ac65a4c 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,9 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2684,6 +2684,10 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6580,8 +6584,9 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6607,6 +6612,10 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1b787fe031..cc942b9c12 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,18 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern Recognition PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern Recognition PATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern Recognition DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Mon_Jun_26_17_45_07_2023_724)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v2-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v2 3/7] Row pattern recognition patch (planner).
@ 2023-06-26 08:05 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-06-26 08:05 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 19 ++++++++++++++-----
src/include/nodes/plannodes.h | 12 ++++++++++++
2 files changed, 26 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 4bb38160b3..c10ac65a4c 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,9 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2684,6 +2684,10 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6580,8 +6584,9 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6607,6 +6612,10 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1b787fe031..cc942b9c12 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,18 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern Recognition PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern Recognition PATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern Recognition DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Mon_Jun_26_17_45_07_2023_724)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v2-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v3 3/7] Row pattern recognition patch (planner).
@ 2023-07-26 10:49 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-07-26 10:49 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 19 ++++++++++++++-----
src/include/nodes/plannodes.h | 12 ++++++++++++
2 files changed, 26 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index af48109058..4b1ae0fb21 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,9 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2679,6 +2679,10 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6582,8 +6586,9 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6609,6 +6614,10 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1b787fe031..cc942b9c12 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,18 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern Recognition PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern Recognition PATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern Recognition DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Wed_Jul_26_21_21_34_2023_317)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v3-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v3 3/7] Row pattern recognition patch (planner).
@ 2023-07-26 10:49 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-07-26 10:49 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 19 ++++++++++++++-----
src/include/nodes/plannodes.h | 12 ++++++++++++
2 files changed, 26 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index af48109058..4b1ae0fb21 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,9 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2679,6 +2679,10 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6582,8 +6586,9 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6609,6 +6614,10 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1b787fe031..cc942b9c12 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,18 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern Recognition PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern Recognition PATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern Recognition DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Wed_Jul_26_21_21_34_2023_317)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v3-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v3 3/7] Row pattern recognition patch (planner).
@ 2023-07-26 10:49 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-07-26 10:49 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 19 ++++++++++++++-----
src/include/nodes/plannodes.h | 12 ++++++++++++
2 files changed, 26 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index af48109058..4b1ae0fb21 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,9 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2679,6 +2679,10 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6582,8 +6586,9 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6609,6 +6614,10 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1b787fe031..cc942b9c12 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,18 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern Recognition PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern Recognition PATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern Recognition DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Wed_Jul_26_21_21_34_2023_317)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v3-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v3 3/7] Row pattern recognition patch (planner).
@ 2023-07-26 10:49 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-07-26 10:49 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 19 ++++++++++++++-----
src/include/nodes/plannodes.h | 12 ++++++++++++
2 files changed, 26 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index af48109058..4b1ae0fb21 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,9 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2679,6 +2679,10 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6582,8 +6586,9 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6609,6 +6614,10 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1b787fe031..cc942b9c12 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,18 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern Recognition PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern Recognition PATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern Recognition DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Wed_Jul_26_21_21_34_2023_317)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v3-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v3 3/7] Row pattern recognition patch (planner).
@ 2023-07-26 10:49 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-07-26 10:49 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 19 ++++++++++++++-----
src/include/nodes/plannodes.h | 12 ++++++++++++
2 files changed, 26 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index af48109058..4b1ae0fb21 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,9 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2679,6 +2679,10 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6582,8 +6586,9 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6609,6 +6614,10 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1b787fe031..cc942b9c12 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,18 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern Recognition PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern Recognition PATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern Recognition DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Wed_Jul_26_21_21_34_2023_317)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v3-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v4 3/7] Row pattern recognition patch (planner).
@ 2023-08-09 07:56 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-08-09 07:56 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++++++-----
src/backend/optimizer/plan/setrefs.c | 23 +++++++++++++++++++++++
src/include/nodes/plannodes.h | 15 +++++++++++++++
3 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index af48109058..828d8d5b62 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2679,6 +2680,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6582,8 +6588,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6609,6 +6617,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 97fa561e4e..2ed00b5d41 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -2456,6 +2456,29 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes reference outputs of a subplan.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1b787fe031..19815a98bb 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Wed_Aug__9_17_41_12_2023_134)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v4-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v4 3/7] Row pattern recognition patch (planner).
@ 2023-08-09 07:56 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-08-09 07:56 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++++++-----
src/backend/optimizer/plan/setrefs.c | 23 +++++++++++++++++++++++
src/include/nodes/plannodes.h | 15 +++++++++++++++
3 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index af48109058..828d8d5b62 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2679,6 +2680,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6582,8 +6588,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6609,6 +6617,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 97fa561e4e..2ed00b5d41 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -2456,6 +2456,29 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes reference outputs of a subplan.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1b787fe031..19815a98bb 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Wed_Aug__9_17_41_12_2023_134)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v4-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v4 3/7] Row pattern recognition patch (planner).
@ 2023-08-09 07:56 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-08-09 07:56 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++++++-----
src/backend/optimizer/plan/setrefs.c | 23 +++++++++++++++++++++++
src/include/nodes/plannodes.h | 15 +++++++++++++++
3 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index af48109058..828d8d5b62 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2679,6 +2680,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6582,8 +6588,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6609,6 +6617,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 97fa561e4e..2ed00b5d41 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -2456,6 +2456,29 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes reference outputs of a subplan.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1b787fe031..19815a98bb 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Wed_Aug__9_17_41_12_2023_134)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v4-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v4 3/7] Row pattern recognition patch (planner).
@ 2023-08-09 07:56 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-08-09 07:56 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++++++-----
src/backend/optimizer/plan/setrefs.c | 23 +++++++++++++++++++++++
src/include/nodes/plannodes.h | 15 +++++++++++++++
3 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index af48109058..828d8d5b62 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2679,6 +2680,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6582,8 +6588,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6609,6 +6617,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 97fa561e4e..2ed00b5d41 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -2456,6 +2456,29 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes reference outputs of a subplan.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1b787fe031..19815a98bb 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Wed_Aug__9_17_41_12_2023_134)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v4-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v4 3/7] Row pattern recognition patch (planner).
@ 2023-08-09 07:56 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-08-09 07:56 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++++++-----
src/backend/optimizer/plan/setrefs.c | 23 +++++++++++++++++++++++
src/include/nodes/plannodes.h | 15 +++++++++++++++
3 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index af48109058..828d8d5b62 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2679,6 +2680,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6582,8 +6588,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6609,6 +6617,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 97fa561e4e..2ed00b5d41 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -2456,6 +2456,29 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes reference outputs of a subplan.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1b787fe031..19815a98bb 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Wed_Aug__9_17_41_12_2023_134)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v4-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v4 3/7] Row pattern recognition patch (planner).
@ 2023-08-09 07:56 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-08-09 07:56 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++++++-----
src/backend/optimizer/plan/setrefs.c | 23 +++++++++++++++++++++++
src/include/nodes/plannodes.h | 15 +++++++++++++++
3 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index af48109058..828d8d5b62 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2679,6 +2680,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6582,8 +6588,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6609,6 +6617,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 97fa561e4e..2ed00b5d41 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -2456,6 +2456,29 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes reference outputs of a subplan.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1b787fe031..19815a98bb 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Wed_Aug__9_17_41_12_2023_134)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v4-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v5 3/7] Row pattern recognition patch (planner).
@ 2023-09-02 06:32 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-09-02 06:32 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++++++-----
src/backend/optimizer/plan/setrefs.c | 23 +++++++++++++++++++++++
src/include/nodes/plannodes.h | 15 +++++++++++++++
3 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 34ca6d4ac2..e3c07ded65 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2698,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6601,8 +6607,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6628,6 +6636,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 97fa561e4e..2ed00b5d41 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -2456,6 +2456,29 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes reference outputs of a subplan.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1b787fe031..19815a98bb 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Sat_Sep__2_15_52_35_2023_273)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v5-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v5 3/7] Row pattern recognition patch (planner).
@ 2023-09-02 06:32 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-09-02 06:32 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++++++-----
src/backend/optimizer/plan/setrefs.c | 23 +++++++++++++++++++++++
src/include/nodes/plannodes.h | 15 +++++++++++++++
3 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 34ca6d4ac2..e3c07ded65 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2698,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6601,8 +6607,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6628,6 +6636,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 97fa561e4e..2ed00b5d41 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -2456,6 +2456,29 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes reference outputs of a subplan.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1b787fe031..19815a98bb 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Sat_Sep__2_15_52_35_2023_273)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v5-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v5 3/7] Row pattern recognition patch (planner).
@ 2023-09-02 06:32 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-09-02 06:32 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++++++-----
src/backend/optimizer/plan/setrefs.c | 23 +++++++++++++++++++++++
src/include/nodes/plannodes.h | 15 +++++++++++++++
3 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 34ca6d4ac2..e3c07ded65 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2698,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6601,8 +6607,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6628,6 +6636,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 97fa561e4e..2ed00b5d41 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -2456,6 +2456,29 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes reference outputs of a subplan.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1b787fe031..19815a98bb 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Sat_Sep__2_15_52_35_2023_273)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v5-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v5 3/7] Row pattern recognition patch (planner).
@ 2023-09-02 06:32 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-09-02 06:32 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++++++-----
src/backend/optimizer/plan/setrefs.c | 23 +++++++++++++++++++++++
src/include/nodes/plannodes.h | 15 +++++++++++++++
3 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 34ca6d4ac2..e3c07ded65 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2698,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6601,8 +6607,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6628,6 +6636,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 97fa561e4e..2ed00b5d41 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -2456,6 +2456,29 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes reference outputs of a subplan.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1b787fe031..19815a98bb 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Sat_Sep__2_15_52_35_2023_273)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v5-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v5 3/7] Row pattern recognition patch (planner).
@ 2023-09-02 06:32 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-09-02 06:32 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++++++-----
src/backend/optimizer/plan/setrefs.c | 23 +++++++++++++++++++++++
src/include/nodes/plannodes.h | 15 +++++++++++++++
3 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 34ca6d4ac2..e3c07ded65 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2698,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6601,8 +6607,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6628,6 +6636,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 97fa561e4e..2ed00b5d41 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -2456,6 +2456,29 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes reference outputs of a subplan.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1b787fe031..19815a98bb 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Sat_Sep__2_15_52_35_2023_273)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v5-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v5 3/7] Row pattern recognition patch (planner).
@ 2023-09-02 06:32 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-09-02 06:32 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++++++-----
src/backend/optimizer/plan/setrefs.c | 23 +++++++++++++++++++++++
src/include/nodes/plannodes.h | 15 +++++++++++++++
3 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 34ca6d4ac2..e3c07ded65 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2698,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6601,8 +6607,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6628,6 +6636,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 97fa561e4e..2ed00b5d41 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -2456,6 +2456,29 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes reference outputs of a subplan.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1b787fe031..19815a98bb 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Sat_Sep__2_15_52_35_2023_273)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v5-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v6 3/7] Row pattern recognition patch (planner).
@ 2023-09-12 05:22 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-09-12 05:22 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++++++-----
src/backend/optimizer/plan/setrefs.c | 23 +++++++++++++++++++++++
src/include/nodes/plannodes.h | 15 +++++++++++++++
3 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 34ca6d4ac2..469fcd156b 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2698,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6601,8 +6607,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6628,6 +6636,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 97fa561e4e..2ed00b5d41 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -2456,6 +2456,29 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes reference outputs of a subplan.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1b787fe031..afa27bb45a 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Tue_Sep_12_15_18_43_2023_359)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v6-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v6 3/7] Row pattern recognition patch (planner).
@ 2023-09-12 05:22 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-09-12 05:22 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++++++-----
src/backend/optimizer/plan/setrefs.c | 23 +++++++++++++++++++++++
src/include/nodes/plannodes.h | 15 +++++++++++++++
3 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 34ca6d4ac2..469fcd156b 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2698,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6601,8 +6607,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6628,6 +6636,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 97fa561e4e..2ed00b5d41 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -2456,6 +2456,29 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes reference outputs of a subplan.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1b787fe031..afa27bb45a 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Tue_Sep_12_15_18_43_2023_359)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v6-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v6 3/7] Row pattern recognition patch (planner).
@ 2023-09-12 05:22 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-09-12 05:22 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++++++-----
src/backend/optimizer/plan/setrefs.c | 23 +++++++++++++++++++++++
src/include/nodes/plannodes.h | 15 +++++++++++++++
3 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 34ca6d4ac2..469fcd156b 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2698,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6601,8 +6607,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6628,6 +6636,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 97fa561e4e..2ed00b5d41 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -2456,6 +2456,29 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes reference outputs of a subplan.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1b787fe031..afa27bb45a 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Tue_Sep_12_15_18_43_2023_359)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v6-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v6 3/7] Row pattern recognition patch (planner).
@ 2023-09-12 05:22 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-09-12 05:22 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++++++-----
src/backend/optimizer/plan/setrefs.c | 23 +++++++++++++++++++++++
src/include/nodes/plannodes.h | 15 +++++++++++++++
3 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 34ca6d4ac2..469fcd156b 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2698,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6601,8 +6607,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6628,6 +6636,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 97fa561e4e..2ed00b5d41 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -2456,6 +2456,29 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes reference outputs of a subplan.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1b787fe031..afa27bb45a 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Tue_Sep_12_15_18_43_2023_359)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v6-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v6 3/7] Row pattern recognition patch (planner).
@ 2023-09-12 05:22 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-09-12 05:22 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++++++-----
src/backend/optimizer/plan/setrefs.c | 23 +++++++++++++++++++++++
src/include/nodes/plannodes.h | 15 +++++++++++++++
3 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 34ca6d4ac2..469fcd156b 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2698,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6601,8 +6607,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6628,6 +6636,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 97fa561e4e..2ed00b5d41 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -2456,6 +2456,29 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes reference outputs of a subplan.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1b787fe031..afa27bb45a 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Tue_Sep_12_15_18_43_2023_359)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v6-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v6 3/7] Row pattern recognition patch (planner).
@ 2023-09-12 05:22 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-09-12 05:22 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++++++-----
src/backend/optimizer/plan/setrefs.c | 23 +++++++++++++++++++++++
src/include/nodes/plannodes.h | 15 +++++++++++++++
3 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 34ca6d4ac2..469fcd156b 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2698,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6601,8 +6607,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6628,6 +6636,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 97fa561e4e..2ed00b5d41 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -2456,6 +2456,29 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes reference outputs of a subplan.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1b787fe031..afa27bb45a 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Tue_Sep_12_15_18_43_2023_359)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v6-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v6 3/7] Row pattern recognition patch (planner).
@ 2023-09-12 05:22 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-09-12 05:22 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++++++-----
src/backend/optimizer/plan/setrefs.c | 23 +++++++++++++++++++++++
src/include/nodes/plannodes.h | 15 +++++++++++++++
3 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 34ca6d4ac2..469fcd156b 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2698,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6601,8 +6607,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6628,6 +6636,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 97fa561e4e..2ed00b5d41 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -2456,6 +2456,29 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes reference outputs of a subplan.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1b787fe031..afa27bb45a 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Tue_Sep_12_15_18_43_2023_359)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v6-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v7 3/7] Row pattern recognition patch (planner).
@ 2023-09-22 04:53 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-09-22 04:53 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++++++-----
src/backend/optimizer/plan/setrefs.c | 23 +++++++++++++++++++++++
src/include/nodes/plannodes.h | 15 +++++++++++++++
3 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 34ca6d4ac2..469fcd156b 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2698,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6601,8 +6607,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6628,6 +6636,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 5700bfb5cd..648bf5a425 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -2456,6 +2456,29 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes reference outputs of a subplan.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1b787fe031..afa27bb45a 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Fri_Sep_22_14_16_40_2023_530)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v7-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v7 3/7] Row pattern recognition patch (planner).
@ 2023-09-22 04:53 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-09-22 04:53 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++++++-----
src/backend/optimizer/plan/setrefs.c | 23 +++++++++++++++++++++++
src/include/nodes/plannodes.h | 15 +++++++++++++++
3 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 34ca6d4ac2..469fcd156b 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2698,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6601,8 +6607,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6628,6 +6636,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 5700bfb5cd..648bf5a425 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -2456,6 +2456,29 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes reference outputs of a subplan.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1b787fe031..afa27bb45a 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Fri_Sep_22_14_16_40_2023_530)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v7-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v7 3/7] Row pattern recognition patch (planner).
@ 2023-09-22 04:53 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-09-22 04:53 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++++++-----
src/backend/optimizer/plan/setrefs.c | 23 +++++++++++++++++++++++
src/include/nodes/plannodes.h | 15 +++++++++++++++
3 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 34ca6d4ac2..469fcd156b 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2698,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6601,8 +6607,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6628,6 +6636,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 5700bfb5cd..648bf5a425 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -2456,6 +2456,29 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes reference outputs of a subplan.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1b787fe031..afa27bb45a 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Fri_Sep_22_14_16_40_2023_530)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v7-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v7 3/7] Row pattern recognition patch (planner).
@ 2023-09-22 04:53 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-09-22 04:53 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++++++-----
src/backend/optimizer/plan/setrefs.c | 23 +++++++++++++++++++++++
src/include/nodes/plannodes.h | 15 +++++++++++++++
3 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 34ca6d4ac2..469fcd156b 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2698,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6601,8 +6607,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6628,6 +6636,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 5700bfb5cd..648bf5a425 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -2456,6 +2456,29 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes reference outputs of a subplan.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1b787fe031..afa27bb45a 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Fri_Sep_22_14_16_40_2023_530)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v7-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v7 3/7] Row pattern recognition patch (planner).
@ 2023-09-22 04:53 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-09-22 04:53 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++++++-----
src/backend/optimizer/plan/setrefs.c | 23 +++++++++++++++++++++++
src/include/nodes/plannodes.h | 15 +++++++++++++++
3 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 34ca6d4ac2..469fcd156b 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2698,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6601,8 +6607,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6628,6 +6636,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 5700bfb5cd..648bf5a425 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -2456,6 +2456,29 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes reference outputs of a subplan.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1b787fe031..afa27bb45a 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Fri_Sep_22_14_16_40_2023_530)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v7-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v8 3/7] Row pattern recognition patch (planner).
@ 2023-09-25 05:01 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-09-25 05:01 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++++++-----
src/backend/optimizer/plan/setrefs.c | 23 +++++++++++++++++++++++
src/include/nodes/plannodes.h | 15 +++++++++++++++
3 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 34ca6d4ac2..469fcd156b 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2698,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6601,8 +6607,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6628,6 +6636,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 5700bfb5cd..648bf5a425 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -2456,6 +2456,29 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes reference outputs of a subplan.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1b787fe031..afa27bb45a 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Mon_Sep_25_14_26_30_2023_752)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v8-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v8 3/7] Row pattern recognition patch (planner).
@ 2023-09-25 05:01 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-09-25 05:01 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++++++-----
src/backend/optimizer/plan/setrefs.c | 23 +++++++++++++++++++++++
src/include/nodes/plannodes.h | 15 +++++++++++++++
3 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 34ca6d4ac2..469fcd156b 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2698,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6601,8 +6607,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6628,6 +6636,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 5700bfb5cd..648bf5a425 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -2456,6 +2456,29 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes reference outputs of a subplan.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1b787fe031..afa27bb45a 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Mon_Sep_25_14_26_30_2023_752)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v8-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v8 3/7] Row pattern recognition patch (planner).
@ 2023-09-25 05:01 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-09-25 05:01 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++++++-----
src/backend/optimizer/plan/setrefs.c | 23 +++++++++++++++++++++++
src/include/nodes/plannodes.h | 15 +++++++++++++++
3 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 34ca6d4ac2..469fcd156b 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2698,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6601,8 +6607,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6628,6 +6636,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 5700bfb5cd..648bf5a425 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -2456,6 +2456,29 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes reference outputs of a subplan.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1b787fe031..afa27bb45a 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Mon_Sep_25_14_26_30_2023_752)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v8-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v8 3/7] Row pattern recognition patch (planner).
@ 2023-09-25 05:01 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-09-25 05:01 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++++++-----
src/backend/optimizer/plan/setrefs.c | 23 +++++++++++++++++++++++
src/include/nodes/plannodes.h | 15 +++++++++++++++
3 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 34ca6d4ac2..469fcd156b 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2698,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6601,8 +6607,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6628,6 +6636,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 5700bfb5cd..648bf5a425 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -2456,6 +2456,29 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes reference outputs of a subplan.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1b787fe031..afa27bb45a 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Mon_Sep_25_14_26_30_2023_752)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v8-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v9 3/7] Row pattern recognition patch (planner).
@ 2023-10-04 05:51 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-10-04 05:51 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++++++-----
src/backend/optimizer/plan/setrefs.c | 23 +++++++++++++++++++++++
src/include/nodes/plannodes.h | 15 +++++++++++++++
3 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 34ca6d4ac2..469fcd156b 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2698,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6601,8 +6607,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6628,6 +6636,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 7962200885..20ce399763 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -2456,6 +2456,29 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes reference outputs of a subplan.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 8cafbf3f8a..e48b59517d 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Wed_Oct__4_15_03_28_2023_821)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v9-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v9 3/7] Row pattern recognition patch (planner).
@ 2023-10-04 05:51 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-10-04 05:51 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++++++-----
src/backend/optimizer/plan/setrefs.c | 23 +++++++++++++++++++++++
src/include/nodes/plannodes.h | 15 +++++++++++++++
3 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 34ca6d4ac2..469fcd156b 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2698,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6601,8 +6607,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6628,6 +6636,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 7962200885..20ce399763 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -2456,6 +2456,29 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes reference outputs of a subplan.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 8cafbf3f8a..e48b59517d 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Wed_Oct__4_15_03_28_2023_821)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v9-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v9 3/7] Row pattern recognition patch (planner).
@ 2023-10-04 05:51 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-10-04 05:51 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++++++-----
src/backend/optimizer/plan/setrefs.c | 23 +++++++++++++++++++++++
src/include/nodes/plannodes.h | 15 +++++++++++++++
3 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 34ca6d4ac2..469fcd156b 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2698,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6601,8 +6607,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6628,6 +6636,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 7962200885..20ce399763 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -2456,6 +2456,29 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes reference outputs of a subplan.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 8cafbf3f8a..e48b59517d 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Wed_Oct__4_15_03_28_2023_821)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v9-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v9 3/7] Row pattern recognition patch (planner).
@ 2023-10-04 05:51 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-10-04 05:51 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++++++-----
src/backend/optimizer/plan/setrefs.c | 23 +++++++++++++++++++++++
src/include/nodes/plannodes.h | 15 +++++++++++++++
3 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 34ca6d4ac2..469fcd156b 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2698,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6601,8 +6607,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6628,6 +6636,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 7962200885..20ce399763 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -2456,6 +2456,29 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes reference outputs of a subplan.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 8cafbf3f8a..e48b59517d 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Wed_Oct__4_15_03_28_2023_821)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v9-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v10 3/7] Row pattern recognition patch (planner).
@ 2023-10-22 02:22 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-10-22 02:22 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++++++-----
src/backend/optimizer/plan/setrefs.c | 23 +++++++++++++++++++++++
src/include/nodes/plannodes.h | 15 +++++++++++++++
3 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 34ca6d4ac2..469fcd156b 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2698,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6601,8 +6607,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6628,6 +6636,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 7962200885..20ce399763 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -2456,6 +2456,29 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes reference outputs of a subplan.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 8cafbf3f8a..e48b59517d 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Sun_Oct_22_11_39_20_2023_140)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v10-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v10 3/7] Row pattern recognition patch (planner).
@ 2023-10-22 02:22 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-10-22 02:22 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++++++-----
src/backend/optimizer/plan/setrefs.c | 23 +++++++++++++++++++++++
src/include/nodes/plannodes.h | 15 +++++++++++++++
3 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 34ca6d4ac2..469fcd156b 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2698,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6601,8 +6607,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6628,6 +6636,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 7962200885..20ce399763 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -2456,6 +2456,29 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes reference outputs of a subplan.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 8cafbf3f8a..e48b59517d 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Sun_Oct_22_11_39_20_2023_140)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v10-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v10 3/7] Row pattern recognition patch (planner).
@ 2023-10-22 02:22 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-10-22 02:22 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++++++-----
src/backend/optimizer/plan/setrefs.c | 23 +++++++++++++++++++++++
src/include/nodes/plannodes.h | 15 +++++++++++++++
3 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 34ca6d4ac2..469fcd156b 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2698,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6601,8 +6607,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6628,6 +6636,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 7962200885..20ce399763 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -2456,6 +2456,29 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes reference outputs of a subplan.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 8cafbf3f8a..e48b59517d 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Sun_Oct_22_11_39_20_2023_140)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v10-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v10 3/7] Row pattern recognition patch (planner).
@ 2023-10-22 02:22 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-10-22 02:22 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++++++-----
src/backend/optimizer/plan/setrefs.c | 23 +++++++++++++++++++++++
src/include/nodes/plannodes.h | 15 +++++++++++++++
3 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 34ca6d4ac2..469fcd156b 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2698,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6601,8 +6607,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6628,6 +6636,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 7962200885..20ce399763 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -2456,6 +2456,29 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes reference outputs of a subplan.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 8cafbf3f8a..e48b59517d 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Sun_Oct_22_11_39_20_2023_140)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v10-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v11 3/7] Row pattern recognition patch (planner).
@ 2023-11-08 06:57 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-11-08 06:57 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++-----
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 4 ++++
src/include/nodes/plannodes.h | 16 ++++++++++++++
4 files changed, 64 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 34ca6d4ac2..469fcd156b 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2698,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6601,8 +6607,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6628,6 +6636,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index fc3709510d..bda99d1c51 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -211,7 +211,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2456,6 +2455,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index 73ff40721c..378644b2c4 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2129,6 +2129,10 @@ perform_pullup_replace_vars(PlannerInfo *root,
if (wc->runCondition != NIL)
wc->runCondition = (List *)
pullup_replace_vars((Node *) wc->runCondition, rvcontext);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
}
if (parse->onConflict)
{
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index d40af8e59f..827b86fea9 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1096,6 +1097,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Wed_Nov__8_16_37_05_2023_872)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v11-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v11 3/7] Row pattern recognition patch (planner).
@ 2023-11-08 06:57 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-11-08 06:57 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++-----
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 4 ++++
src/include/nodes/plannodes.h | 16 ++++++++++++++
4 files changed, 64 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 34ca6d4ac2..469fcd156b 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2698,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6601,8 +6607,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6628,6 +6636,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index fc3709510d..bda99d1c51 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -211,7 +211,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2456,6 +2455,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index 73ff40721c..378644b2c4 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2129,6 +2129,10 @@ perform_pullup_replace_vars(PlannerInfo *root,
if (wc->runCondition != NIL)
wc->runCondition = (List *)
pullup_replace_vars((Node *) wc->runCondition, rvcontext);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
}
if (parse->onConflict)
{
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index d40af8e59f..827b86fea9 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1096,6 +1097,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Wed_Nov__8_16_37_05_2023_872)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v11-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v11 3/7] Row pattern recognition patch (planner).
@ 2023-11-08 06:57 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-11-08 06:57 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++-----
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 4 ++++
src/include/nodes/plannodes.h | 16 ++++++++++++++
4 files changed, 64 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 34ca6d4ac2..469fcd156b 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2698,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6601,8 +6607,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6628,6 +6636,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index fc3709510d..bda99d1c51 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -211,7 +211,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2456,6 +2455,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index 73ff40721c..378644b2c4 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2129,6 +2129,10 @@ perform_pullup_replace_vars(PlannerInfo *root,
if (wc->runCondition != NIL)
wc->runCondition = (List *)
pullup_replace_vars((Node *) wc->runCondition, rvcontext);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
}
if (parse->onConflict)
{
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index d40af8e59f..827b86fea9 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1096,6 +1097,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Wed_Nov__8_16_37_05_2023_872)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v11-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v12 3/7] Row pattern recognition patch (planner).
@ 2023-12-04 11:23 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-12-04 11:23 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++-----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 4 ++++
src/include/nodes/plannodes.h | 16 ++++++++++++++
5 files changed, 67 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 34ca6d4ac2..469fcd156b 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2698,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6601,8 +6607,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6628,6 +6636,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index a8cea5efe1..7d4324e5e3 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -868,6 +868,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse,
wc->runCondition = (List *) preprocess_expression(root,
(Node *) wc->runCondition,
EXPRKIND_TARGET);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 4bb68ac90e..aa781494d3 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -211,7 +211,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2456,6 +2455,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index 73ff40721c..378644b2c4 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2129,6 +2129,10 @@ perform_pullup_replace_vars(PlannerInfo *root,
if (wc->runCondition != NIL)
wc->runCondition = (List *)
pullup_replace_vars((Node *) wc->runCondition, rvcontext);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
}
if (parse->onConflict)
{
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index d40af8e59f..827b86fea9 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1096,6 +1097,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Fri_Dec__8_10_16_13_2023_489)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v12-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v12 3/7] Row pattern recognition patch (planner).
@ 2023-12-04 11:23 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-12-04 11:23 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++-----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 4 ++++
src/include/nodes/plannodes.h | 16 ++++++++++++++
5 files changed, 67 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 34ca6d4ac2..469fcd156b 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2698,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6601,8 +6607,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6628,6 +6636,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index a8cea5efe1..7d4324e5e3 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -868,6 +868,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse,
wc->runCondition = (List *) preprocess_expression(root,
(Node *) wc->runCondition,
EXPRKIND_TARGET);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 4bb68ac90e..aa781494d3 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -211,7 +211,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2456,6 +2455,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index 73ff40721c..378644b2c4 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2129,6 +2129,10 @@ perform_pullup_replace_vars(PlannerInfo *root,
if (wc->runCondition != NIL)
wc->runCondition = (List *)
pullup_replace_vars((Node *) wc->runCondition, rvcontext);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
}
if (parse->onConflict)
{
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index d40af8e59f..827b86fea9 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1096,6 +1097,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Fri_Dec__8_10_16_13_2023_489)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v12-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v12 3/7] Row pattern recognition patch (planner).
@ 2023-12-04 11:23 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2023-12-04 11:23 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++-----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 4 ++++
src/include/nodes/plannodes.h | 16 ++++++++++++++
5 files changed, 67 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 34ca6d4ac2..469fcd156b 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2698,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6601,8 +6607,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6628,6 +6636,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index a8cea5efe1..7d4324e5e3 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -868,6 +868,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse,
wc->runCondition = (List *) preprocess_expression(root,
(Node *) wc->runCondition,
EXPRKIND_TARGET);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 4bb68ac90e..aa781494d3 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -211,7 +211,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2456,6 +2455,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index 73ff40721c..378644b2c4 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2129,6 +2129,10 @@ perform_pullup_replace_vars(PlannerInfo *root,
if (wc->runCondition != NIL)
wc->runCondition = (List *)
pullup_replace_vars((Node *) wc->runCondition, rvcontext);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
}
if (parse->onConflict)
{
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index d40af8e59f..827b86fea9 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1096,6 +1097,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Fri_Dec__8_10_16_13_2023_489)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v12-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v13 4/8] Row pattern recognition patch (planner).
@ 2024-01-22 09:45 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-01-22 09:45 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++-----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 4 ++++
src/include/nodes/plannodes.h | 16 ++++++++++++++
5 files changed, 67 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index ca619eab94..3c7fd3867b 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2698,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6601,8 +6607,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6628,6 +6636,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 2e2458b128..98fdfb06e3 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -868,6 +868,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse,
wc->runCondition = (List *) preprocess_expression(root,
(Node *) wc->runCondition,
EXPRKIND_TARGET);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 22a1fa29f3..d96bf6d3a0 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -211,7 +211,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2456,6 +2455,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index aa83dd3636..95d7399ab4 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2129,6 +2129,10 @@ perform_pullup_replace_vars(PlannerInfo *root,
if (wc->runCondition != NIL)
wc->runCondition = (List *)
pullup_replace_vars((Node *) wc->runCondition, rvcontext);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
}
if (parse->onConflict)
{
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index b4ef6bc44c..1b928e5a49 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1096,6 +1097,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Mon_Jan_22_19_26_18_2024_011)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v13-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v13 4/8] Row pattern recognition patch (planner).
@ 2024-01-22 09:45 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-01-22 09:45 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++-----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 4 ++++
src/include/nodes/plannodes.h | 16 ++++++++++++++
5 files changed, 67 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index ca619eab94..3c7fd3867b 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2698,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6601,8 +6607,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6628,6 +6636,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 2e2458b128..98fdfb06e3 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -868,6 +868,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse,
wc->runCondition = (List *) preprocess_expression(root,
(Node *) wc->runCondition,
EXPRKIND_TARGET);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 22a1fa29f3..d96bf6d3a0 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -211,7 +211,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2456,6 +2455,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index aa83dd3636..95d7399ab4 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2129,6 +2129,10 @@ perform_pullup_replace_vars(PlannerInfo *root,
if (wc->runCondition != NIL)
wc->runCondition = (List *)
pullup_replace_vars((Node *) wc->runCondition, rvcontext);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
}
if (parse->onConflict)
{
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index b4ef6bc44c..1b928e5a49 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1096,6 +1097,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Mon_Jan_22_19_26_18_2024_011)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v13-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v13 4/8] Row pattern recognition patch (planner).
@ 2024-01-22 09:45 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-01-22 09:45 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++-----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 4 ++++
src/include/nodes/plannodes.h | 16 ++++++++++++++
5 files changed, 67 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index ca619eab94..3c7fd3867b 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2698,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6601,8 +6607,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6628,6 +6636,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 2e2458b128..98fdfb06e3 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -868,6 +868,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse,
wc->runCondition = (List *) preprocess_expression(root,
(Node *) wc->runCondition,
EXPRKIND_TARGET);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 22a1fa29f3..d96bf6d3a0 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -211,7 +211,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2456,6 +2455,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index aa83dd3636..95d7399ab4 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2129,6 +2129,10 @@ perform_pullup_replace_vars(PlannerInfo *root,
if (wc->runCondition != NIL)
wc->runCondition = (List *)
pullup_replace_vars((Node *) wc->runCondition, rvcontext);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
}
if (parse->onConflict)
{
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index b4ef6bc44c..1b928e5a49 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1096,6 +1097,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Mon_Jan_22_19_26_18_2024_011)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v13-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v14 4/8] Row pattern recognition patch (planner).
@ 2024-02-28 13:59 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-02-28 13:59 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 24 +++++++++++++++-----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 4 ++++
src/include/nodes/plannodes.h | 19 ++++++++++++++++
5 files changed, 71 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 610f4a56d6..a9138e3395 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,11 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp,
+ List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2698,6 +2700,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6610,8 +6617,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6637,6 +6646,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index be4e182869..1ddfc3ed2d 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -870,6 +870,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse,
wc->runCondition = (List *) preprocess_expression(root,
(Node *) wc->runCondition,
EXPRKIND_TARGET);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 22a1fa29f3..6ab4eb759e 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -211,7 +211,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2456,6 +2455,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index aa83dd3636..95d7399ab4 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2129,6 +2129,10 @@ perform_pullup_replace_vars(PlannerInfo *root,
if (wc->runCondition != NIL)
wc->runCondition = (List *)
pullup_replace_vars((Node *) wc->runCondition, rvcontext);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
}
if (parse->onConflict)
{
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index b4ef6bc44c..3425796212 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1096,6 +1097,24 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /*
+ * Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
+ * String)
+ */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Thu_Feb_29_09_19_54_2024_640)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v14-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v14 4/8] Row pattern recognition patch (planner).
@ 2024-02-28 13:59 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-02-28 13:59 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 24 +++++++++++++++-----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 4 ++++
src/include/nodes/plannodes.h | 19 ++++++++++++++++
5 files changed, 71 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 610f4a56d6..a9138e3395 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,11 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp,
+ List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2698,6 +2700,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6610,8 +6617,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6637,6 +6646,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index be4e182869..1ddfc3ed2d 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -870,6 +870,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse,
wc->runCondition = (List *) preprocess_expression(root,
(Node *) wc->runCondition,
EXPRKIND_TARGET);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 22a1fa29f3..6ab4eb759e 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -211,7 +211,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2456,6 +2455,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index aa83dd3636..95d7399ab4 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2129,6 +2129,10 @@ perform_pullup_replace_vars(PlannerInfo *root,
if (wc->runCondition != NIL)
wc->runCondition = (List *)
pullup_replace_vars((Node *) wc->runCondition, rvcontext);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
}
if (parse->onConflict)
{
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index b4ef6bc44c..3425796212 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1096,6 +1097,24 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /*
+ * Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
+ * String)
+ */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Thu_Feb_29_09_19_54_2024_640)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v14-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v14 4/8] Row pattern recognition patch (planner).
@ 2024-02-28 13:59 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-02-28 13:59 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 24 +++++++++++++++-----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 4 ++++
src/include/nodes/plannodes.h | 19 ++++++++++++++++
5 files changed, 71 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 610f4a56d6..a9138e3395 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,11 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp,
+ List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2698,6 +2700,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6610,8 +6617,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6637,6 +6646,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index be4e182869..1ddfc3ed2d 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -870,6 +870,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse,
wc->runCondition = (List *) preprocess_expression(root,
(Node *) wc->runCondition,
EXPRKIND_TARGET);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 22a1fa29f3..6ab4eb759e 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -211,7 +211,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2456,6 +2455,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index aa83dd3636..95d7399ab4 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2129,6 +2129,10 @@ perform_pullup_replace_vars(PlannerInfo *root,
if (wc->runCondition != NIL)
wc->runCondition = (List *)
pullup_replace_vars((Node *) wc->runCondition, rvcontext);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
}
if (parse->onConflict)
{
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index b4ef6bc44c..3425796212 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1096,6 +1097,24 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /*
+ * Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
+ * String)
+ */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Thu_Feb_29_09_19_54_2024_640)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v14-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v15 4/8] Row pattern recognition patch (planner).
@ 2024-03-28 10:30 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-03-28 10:30 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 24 +++++++++++++++-----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 4 ++++
src/include/nodes/plannodes.h | 19 ++++++++++++++++
5 files changed, 71 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 5f479fc56c..fe51ad351e 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -287,9 +287,11 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp,
+ List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2699,6 +2701,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6627,8 +6634,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6654,6 +6663,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 38d070fa00..82c370c4b4 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -869,6 +869,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse,
wc->runCondition = (List *) preprocess_expression(root,
(Node *) wc->runCondition,
EXPRKIND_TARGET);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 42603dbc7c..f7abb2be96 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -210,7 +210,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2455,6 +2454,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index 300691cc4d..3220072a51 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2147,6 +2147,10 @@ perform_pullup_replace_vars(PlannerInfo *root,
if (wc->runCondition != NIL)
wc->runCondition = (List *)
pullup_replace_vars((Node *) wc->runCondition, rvcontext);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
}
if (parse->onConflict)
{
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 7f3db5105d..b0e50ae886 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1096,6 +1097,24 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /*
+ * Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
+ * String)
+ */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Thu_Mar_28_19_59_25_2024_076)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v15-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v15 4/8] Row pattern recognition patch (planner).
@ 2024-03-28 10:30 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-03-28 10:30 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 24 +++++++++++++++-----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 4 ++++
src/include/nodes/plannodes.h | 19 ++++++++++++++++
5 files changed, 71 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 5f479fc56c..fe51ad351e 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -287,9 +287,11 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp,
+ List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2699,6 +2701,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6627,8 +6634,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6654,6 +6663,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 38d070fa00..82c370c4b4 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -869,6 +869,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse,
wc->runCondition = (List *) preprocess_expression(root,
(Node *) wc->runCondition,
EXPRKIND_TARGET);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 42603dbc7c..f7abb2be96 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -210,7 +210,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2455,6 +2454,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index 300691cc4d..3220072a51 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2147,6 +2147,10 @@ perform_pullup_replace_vars(PlannerInfo *root,
if (wc->runCondition != NIL)
wc->runCondition = (List *)
pullup_replace_vars((Node *) wc->runCondition, rvcontext);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
}
if (parse->onConflict)
{
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 7f3db5105d..b0e50ae886 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1096,6 +1097,24 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /*
+ * Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
+ * String)
+ */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Thu_Mar_28_19_59_25_2024_076)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v15-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v15 4/8] Row pattern recognition patch (planner).
@ 2024-03-28 10:30 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-03-28 10:30 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 24 +++++++++++++++-----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 4 ++++
src/include/nodes/plannodes.h | 19 ++++++++++++++++
5 files changed, 71 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 5f479fc56c..fe51ad351e 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -287,9 +287,11 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp,
+ List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2699,6 +2701,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6627,8 +6634,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6654,6 +6663,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 38d070fa00..82c370c4b4 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -869,6 +869,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse,
wc->runCondition = (List *) preprocess_expression(root,
(Node *) wc->runCondition,
EXPRKIND_TARGET);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 42603dbc7c..f7abb2be96 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -210,7 +210,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2455,6 +2454,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index 300691cc4d..3220072a51 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2147,6 +2147,10 @@ perform_pullup_replace_vars(PlannerInfo *root,
if (wc->runCondition != NIL)
wc->runCondition = (List *)
pullup_replace_vars((Node *) wc->runCondition, rvcontext);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
}
if (parse->onConflict)
{
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 7f3db5105d..b0e50ae886 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1096,6 +1097,24 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /*
+ * Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
+ * String)
+ */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Thu_Mar_28_19_59_25_2024_076)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v15-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v15 4/8] Row pattern recognition patch (planner).
@ 2024-03-28 10:30 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-03-28 10:30 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 24 +++++++++++++++-----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 4 ++++
src/include/nodes/plannodes.h | 19 ++++++++++++++++
5 files changed, 71 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 5f479fc56c..fe51ad351e 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -287,9 +287,11 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp,
+ List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2699,6 +2701,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6627,8 +6634,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6654,6 +6663,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 38d070fa00..82c370c4b4 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -869,6 +869,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse,
wc->runCondition = (List *) preprocess_expression(root,
(Node *) wc->runCondition,
EXPRKIND_TARGET);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 42603dbc7c..f7abb2be96 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -210,7 +210,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2455,6 +2454,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index 300691cc4d..3220072a51 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2147,6 +2147,10 @@ perform_pullup_replace_vars(PlannerInfo *root,
if (wc->runCondition != NIL)
wc->runCondition = (List *)
pullup_replace_vars((Node *) wc->runCondition, rvcontext);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
}
if (parse->onConflict)
{
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 7f3db5105d..b0e50ae886 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1096,6 +1097,24 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /*
+ * Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
+ * String)
+ */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Thu_Mar_28_19_59_25_2024_076)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v15-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v15 4/8] Row pattern recognition patch (planner).
@ 2024-03-28 10:30 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-03-28 10:30 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 24 +++++++++++++++-----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 4 ++++
src/include/nodes/plannodes.h | 19 ++++++++++++++++
5 files changed, 71 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 5f479fc56c..fe51ad351e 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -287,9 +287,11 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp,
+ List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2699,6 +2701,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6627,8 +6634,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6654,6 +6663,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 38d070fa00..82c370c4b4 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -869,6 +869,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse,
wc->runCondition = (List *) preprocess_expression(root,
(Node *) wc->runCondition,
EXPRKIND_TARGET);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 42603dbc7c..f7abb2be96 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -210,7 +210,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2455,6 +2454,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index 300691cc4d..3220072a51 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2147,6 +2147,10 @@ perform_pullup_replace_vars(PlannerInfo *root,
if (wc->runCondition != NIL)
wc->runCondition = (List *)
pullup_replace_vars((Node *) wc->runCondition, rvcontext);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
}
if (parse->onConflict)
{
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 7f3db5105d..b0e50ae886 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1096,6 +1097,24 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /*
+ * Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
+ * String)
+ */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Thu_Mar_28_19_59_25_2024_076)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v15-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v16 4/8] Row pattern recognition patch (planner).
@ 2024-04-12 06:49 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-04-12 06:49 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 24 +++++++++++++++-----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 4 ++++
src/include/nodes/plannodes.h | 19 ++++++++++++++++
5 files changed, 71 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 3b77886567..c8d96be7d7 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -287,9 +287,11 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp,
+ List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2700,6 +2702,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6629,8 +6636,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6656,6 +6665,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 5320da51a0..5eb66c709b 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -873,6 +873,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root,
wc->runCondition = (List *) preprocess_expression(root,
(Node *) wc->runCondition,
EXPRKIND_TARGET);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 37abcb4701..cd0e7c57d8 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -210,7 +210,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2471,6 +2470,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index 4badb6ff58..1c34360c7c 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2178,6 +2178,10 @@ perform_pullup_replace_vars(PlannerInfo *root,
if (wc->runCondition != NIL)
wc->runCondition = (List *)
pullup_replace_vars((Node *) wc->runCondition, rvcontext);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
}
if (parse->onConflict)
{
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index e025679f89..90441f4d90 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1098,6 +1099,24 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /*
+ * Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
+ * String)
+ */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Fri_Apr_12_16_09_08_2024_262)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v16-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v16 4/8] Row pattern recognition patch (planner).
@ 2024-04-12 06:49 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-04-12 06:49 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 24 +++++++++++++++-----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 4 ++++
src/include/nodes/plannodes.h | 19 ++++++++++++++++
5 files changed, 71 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 3b77886567..c8d96be7d7 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -287,9 +287,11 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp,
+ List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2700,6 +2702,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6629,8 +6636,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6656,6 +6665,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 5320da51a0..5eb66c709b 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -873,6 +873,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root,
wc->runCondition = (List *) preprocess_expression(root,
(Node *) wc->runCondition,
EXPRKIND_TARGET);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 37abcb4701..cd0e7c57d8 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -210,7 +210,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2471,6 +2470,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index 4badb6ff58..1c34360c7c 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2178,6 +2178,10 @@ perform_pullup_replace_vars(PlannerInfo *root,
if (wc->runCondition != NIL)
wc->runCondition = (List *)
pullup_replace_vars((Node *) wc->runCondition, rvcontext);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
}
if (parse->onConflict)
{
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index e025679f89..90441f4d90 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1098,6 +1099,24 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /*
+ * Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
+ * String)
+ */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Fri_Apr_12_16_09_08_2024_262)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v16-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v16 4/8] Row pattern recognition patch (planner).
@ 2024-04-12 06:49 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-04-12 06:49 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 24 +++++++++++++++-----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 4 ++++
src/include/nodes/plannodes.h | 19 ++++++++++++++++
5 files changed, 71 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 3b77886567..c8d96be7d7 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -287,9 +287,11 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp,
+ List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2700,6 +2702,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6629,8 +6636,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6656,6 +6665,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 5320da51a0..5eb66c709b 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -873,6 +873,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root,
wc->runCondition = (List *) preprocess_expression(root,
(Node *) wc->runCondition,
EXPRKIND_TARGET);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 37abcb4701..cd0e7c57d8 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -210,7 +210,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2471,6 +2470,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index 4badb6ff58..1c34360c7c 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2178,6 +2178,10 @@ perform_pullup_replace_vars(PlannerInfo *root,
if (wc->runCondition != NIL)
wc->runCondition = (List *)
pullup_replace_vars((Node *) wc->runCondition, rvcontext);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
}
if (parse->onConflict)
{
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index e025679f89..90441f4d90 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1098,6 +1099,24 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /*
+ * Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
+ * String)
+ */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Fri_Apr_12_16_09_08_2024_262)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v16-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v17 4/8] Row pattern recognition patch (planner).
@ 2024-04-28 11:00 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-04-28 11:00 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 24 +++++++++++++++-----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 4 ++++
src/include/nodes/plannodes.h | 19 ++++++++++++++++
5 files changed, 71 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 3b77886567..c8d96be7d7 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -287,9 +287,11 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp,
+ List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2700,6 +2702,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6629,8 +6636,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6656,6 +6665,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 5320da51a0..5eb66c709b 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -873,6 +873,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root,
wc->runCondition = (List *) preprocess_expression(root,
(Node *) wc->runCondition,
EXPRKIND_TARGET);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 37abcb4701..cd0e7c57d8 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -210,7 +210,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2471,6 +2470,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index 41da670f15..b453977178 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2182,6 +2182,10 @@ perform_pullup_replace_vars(PlannerInfo *root,
if (wc->runCondition != NIL)
wc->runCondition = (List *)
pullup_replace_vars((Node *) wc->runCondition, rvcontext);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
}
if (parse->onConflict)
{
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index e025679f89..90441f4d90 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1098,6 +1099,24 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /*
+ * Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
+ * String)
+ */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Sun_Apr_28_20_28_26_2024_444)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v17-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v17 4/8] Row pattern recognition patch (planner).
@ 2024-04-28 11:00 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-04-28 11:00 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 24 +++++++++++++++-----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 4 ++++
src/include/nodes/plannodes.h | 19 ++++++++++++++++
5 files changed, 71 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 3b77886567..c8d96be7d7 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -287,9 +287,11 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp,
+ List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2700,6 +2702,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6629,8 +6636,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6656,6 +6665,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 5320da51a0..5eb66c709b 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -873,6 +873,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root,
wc->runCondition = (List *) preprocess_expression(root,
(Node *) wc->runCondition,
EXPRKIND_TARGET);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 37abcb4701..cd0e7c57d8 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -210,7 +210,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2471,6 +2470,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index 41da670f15..b453977178 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2182,6 +2182,10 @@ perform_pullup_replace_vars(PlannerInfo *root,
if (wc->runCondition != NIL)
wc->runCondition = (List *)
pullup_replace_vars((Node *) wc->runCondition, rvcontext);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
}
if (parse->onConflict)
{
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index e025679f89..90441f4d90 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1098,6 +1099,24 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /*
+ * Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
+ * String)
+ */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Sun_Apr_28_20_28_26_2024_444)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v17-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v17 4/8] Row pattern recognition patch (planner).
@ 2024-04-28 11:00 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-04-28 11:00 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 24 +++++++++++++++-----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 4 ++++
src/include/nodes/plannodes.h | 19 ++++++++++++++++
5 files changed, 71 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 3b77886567..c8d96be7d7 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -287,9 +287,11 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp,
+ List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2700,6 +2702,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6629,8 +6636,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6656,6 +6665,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 5320da51a0..5eb66c709b 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -873,6 +873,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root,
wc->runCondition = (List *) preprocess_expression(root,
(Node *) wc->runCondition,
EXPRKIND_TARGET);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 37abcb4701..cd0e7c57d8 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -210,7 +210,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2471,6 +2470,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index 41da670f15..b453977178 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2182,6 +2182,10 @@ perform_pullup_replace_vars(PlannerInfo *root,
if (wc->runCondition != NIL)
wc->runCondition = (List *)
pullup_replace_vars((Node *) wc->runCondition, rvcontext);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
}
if (parse->onConflict)
{
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index e025679f89..90441f4d90 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1098,6 +1099,24 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /*
+ * Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
+ * String)
+ */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Sun_Apr_28_20_28_26_2024_444)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v17-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v18 4/8] Row pattern recognition patch (planner).
@ 2024-05-11 07:11 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-05-11 07:11 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 24 +++++++++++++++-----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 9 ++++++++
src/include/nodes/plannodes.h | 19 ++++++++++++++++
5 files changed, 76 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 6b64c4a362..ef2101e216 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -287,9 +287,11 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp,
+ List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2700,6 +2702,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
best_path->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6629,8 +6636,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6656,6 +6665,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 032818423f..a5d17e3fda 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -870,6 +870,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root,
EXPRKIND_LIMIT);
wc->endOffset = preprocess_expression(root, wc->endOffset,
EXPRKIND_LIMIT);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 37abcb4701..cd0e7c57d8 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -210,7 +210,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2471,6 +2470,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index 5482ab85a7..f54db3f044 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2175,6 +2175,15 @@ perform_pullup_replace_vars(PlannerInfo *root,
parse->returningList = (List *)
pullup_replace_vars((Node *) parse->returningList, rvcontext);
+ foreach(lc, parse->windowClause)
+ {
+ WindowClause *wc = lfirst_node(WindowClause, lc);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
+ }
+
if (parse->onConflict)
{
parse->onConflict->onConflictSet = (List *)
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index e025679f89..90441f4d90 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1098,6 +1099,24 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /*
+ * Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
+ * String)
+ */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Sat_May_11_16_23_07_2024_789)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v18-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v18 4/8] Row pattern recognition patch (planner).
@ 2024-05-11 07:11 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-05-11 07:11 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 24 +++++++++++++++-----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 9 ++++++++
src/include/nodes/plannodes.h | 19 ++++++++++++++++
5 files changed, 76 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 6b64c4a362..ef2101e216 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -287,9 +287,11 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp,
+ List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2700,6 +2702,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
best_path->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6629,8 +6636,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6656,6 +6665,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 032818423f..a5d17e3fda 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -870,6 +870,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root,
EXPRKIND_LIMIT);
wc->endOffset = preprocess_expression(root, wc->endOffset,
EXPRKIND_LIMIT);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 37abcb4701..cd0e7c57d8 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -210,7 +210,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2471,6 +2470,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index 5482ab85a7..f54db3f044 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2175,6 +2175,15 @@ perform_pullup_replace_vars(PlannerInfo *root,
parse->returningList = (List *)
pullup_replace_vars((Node *) parse->returningList, rvcontext);
+ foreach(lc, parse->windowClause)
+ {
+ WindowClause *wc = lfirst_node(WindowClause, lc);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
+ }
+
if (parse->onConflict)
{
parse->onConflict->onConflictSet = (List *)
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index e025679f89..90441f4d90 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1098,6 +1099,24 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /*
+ * Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
+ * String)
+ */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Sat_May_11_16_23_07_2024_789)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v18-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v18 4/8] Row pattern recognition patch (planner).
@ 2024-05-11 07:11 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-05-11 07:11 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 24 +++++++++++++++-----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 9 ++++++++
src/include/nodes/plannodes.h | 19 ++++++++++++++++
5 files changed, 76 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 6b64c4a362..ef2101e216 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -287,9 +287,11 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp,
+ List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2700,6 +2702,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
best_path->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6629,8 +6636,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6656,6 +6665,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 032818423f..a5d17e3fda 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -870,6 +870,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root,
EXPRKIND_LIMIT);
wc->endOffset = preprocess_expression(root, wc->endOffset,
EXPRKIND_LIMIT);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 37abcb4701..cd0e7c57d8 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -210,7 +210,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2471,6 +2470,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index 5482ab85a7..f54db3f044 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2175,6 +2175,15 @@ perform_pullup_replace_vars(PlannerInfo *root,
parse->returningList = (List *)
pullup_replace_vars((Node *) parse->returningList, rvcontext);
+ foreach(lc, parse->windowClause)
+ {
+ WindowClause *wc = lfirst_node(WindowClause, lc);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
+ }
+
if (parse->onConflict)
{
parse->onConflict->onConflictSet = (List *)
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index e025679f89..90441f4d90 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1098,6 +1099,24 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /*
+ * Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
+ * String)
+ */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Sat_May_11_16_23_07_2024_789)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v18-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v19 4/8] Row pattern recognition patch (planner).
@ 2024-05-14 23:26 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-05-14 23:26 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 24 +++++++++++++++-----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 9 ++++++++
src/include/nodes/plannodes.h | 19 ++++++++++++++++
5 files changed, 76 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 6b64c4a362..ef2101e216 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -287,9 +287,11 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp,
+ List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2700,6 +2702,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
best_path->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6629,8 +6636,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6656,6 +6665,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 032818423f..a5d17e3fda 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -870,6 +870,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root,
EXPRKIND_LIMIT);
wc->endOffset = preprocess_expression(root, wc->endOffset,
EXPRKIND_LIMIT);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 37abcb4701..cd0e7c57d8 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -210,7 +210,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2471,6 +2470,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index 5482ab85a7..f54db3f044 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2175,6 +2175,15 @@ perform_pullup_replace_vars(PlannerInfo *root,
parse->returningList = (List *)
pullup_replace_vars((Node *) parse->returningList, rvcontext);
+ foreach(lc, parse->windowClause)
+ {
+ WindowClause *wc = lfirst_node(WindowClause, lc);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
+ }
+
if (parse->onConflict)
{
parse->onConflict->onConflictSet = (List *)
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index e025679f89..90441f4d90 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1098,6 +1099,24 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /*
+ * Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
+ * String)
+ */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Wed_May_15_09_02_03_2024_008)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v19-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v19 4/8] Row pattern recognition patch (planner).
@ 2024-05-14 23:26 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-05-14 23:26 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 24 +++++++++++++++-----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 9 ++++++++
src/include/nodes/plannodes.h | 19 ++++++++++++++++
5 files changed, 76 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 6b64c4a362..ef2101e216 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -287,9 +287,11 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp,
+ List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2700,6 +2702,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
best_path->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6629,8 +6636,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6656,6 +6665,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 032818423f..a5d17e3fda 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -870,6 +870,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root,
EXPRKIND_LIMIT);
wc->endOffset = preprocess_expression(root, wc->endOffset,
EXPRKIND_LIMIT);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 37abcb4701..cd0e7c57d8 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -210,7 +210,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2471,6 +2470,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index 5482ab85a7..f54db3f044 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2175,6 +2175,15 @@ perform_pullup_replace_vars(PlannerInfo *root,
parse->returningList = (List *)
pullup_replace_vars((Node *) parse->returningList, rvcontext);
+ foreach(lc, parse->windowClause)
+ {
+ WindowClause *wc = lfirst_node(WindowClause, lc);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
+ }
+
if (parse->onConflict)
{
parse->onConflict->onConflictSet = (List *)
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index e025679f89..90441f4d90 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1098,6 +1099,24 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /*
+ * Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
+ * String)
+ */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Wed_May_15_09_02_03_2024_008)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v19-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v19 4/8] Row pattern recognition patch (planner).
@ 2024-05-14 23:26 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-05-14 23:26 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 24 +++++++++++++++-----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 9 ++++++++
src/include/nodes/plannodes.h | 19 ++++++++++++++++
5 files changed, 76 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 6b64c4a362..ef2101e216 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -287,9 +287,11 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp,
+ List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2700,6 +2702,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
best_path->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6629,8 +6636,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6656,6 +6665,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 032818423f..a5d17e3fda 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -870,6 +870,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root,
EXPRKIND_LIMIT);
wc->endOffset = preprocess_expression(root, wc->endOffset,
EXPRKIND_LIMIT);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 37abcb4701..cd0e7c57d8 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -210,7 +210,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2471,6 +2470,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index 5482ab85a7..f54db3f044 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2175,6 +2175,15 @@ perform_pullup_replace_vars(PlannerInfo *root,
parse->returningList = (List *)
pullup_replace_vars((Node *) parse->returningList, rvcontext);
+ foreach(lc, parse->windowClause)
+ {
+ WindowClause *wc = lfirst_node(WindowClause, lc);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
+ }
+
if (parse->onConflict)
{
parse->onConflict->onConflictSet = (List *)
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index e025679f89..90441f4d90 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1098,6 +1099,24 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /*
+ * Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
+ * String)
+ */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Wed_May_15_09_02_03_2024_008)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v19-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v20 4/8] Row pattern recognition patch (planner).
@ 2024-05-24 02:26 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-05-24 02:26 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 24 +++++++++++++++-----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 9 ++++++++
src/include/nodes/plannodes.h | 19 ++++++++++++++++
5 files changed, 76 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 6b64c4a362..ef2101e216 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -287,9 +287,11 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp,
+ List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2700,6 +2702,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
best_path->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6629,8 +6636,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6656,6 +6665,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 032818423f..a5d17e3fda 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -870,6 +870,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root,
EXPRKIND_LIMIT);
wc->endOffset = preprocess_expression(root, wc->endOffset,
EXPRKIND_LIMIT);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 37abcb4701..cd0e7c57d8 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -210,7 +210,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2471,6 +2470,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index 5482ab85a7..f54db3f044 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2175,6 +2175,15 @@ perform_pullup_replace_vars(PlannerInfo *root,
parse->returningList = (List *)
pullup_replace_vars((Node *) parse->returningList, rvcontext);
+ foreach(lc, parse->windowClause)
+ {
+ WindowClause *wc = lfirst_node(WindowClause, lc);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
+ }
+
if (parse->onConflict)
{
parse->onConflict->onConflictSet = (List *)
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1aeeaec95e..5b8d8a6dac 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1098,6 +1099,24 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /*
+ * Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
+ * String)
+ */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Fri_May_24_11_39_19_2024_763)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v20-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v20 4/8] Row pattern recognition patch (planner).
@ 2024-05-24 02:26 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-05-24 02:26 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 24 +++++++++++++++-----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 9 ++++++++
src/include/nodes/plannodes.h | 19 ++++++++++++++++
5 files changed, 76 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 6b64c4a362..ef2101e216 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -287,9 +287,11 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp,
+ List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2700,6 +2702,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
best_path->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6629,8 +6636,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6656,6 +6665,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 032818423f..a5d17e3fda 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -870,6 +870,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root,
EXPRKIND_LIMIT);
wc->endOffset = preprocess_expression(root, wc->endOffset,
EXPRKIND_LIMIT);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 37abcb4701..cd0e7c57d8 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -210,7 +210,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2471,6 +2470,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index 5482ab85a7..f54db3f044 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2175,6 +2175,15 @@ perform_pullup_replace_vars(PlannerInfo *root,
parse->returningList = (List *)
pullup_replace_vars((Node *) parse->returningList, rvcontext);
+ foreach(lc, parse->windowClause)
+ {
+ WindowClause *wc = lfirst_node(WindowClause, lc);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
+ }
+
if (parse->onConflict)
{
parse->onConflict->onConflictSet = (List *)
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1aeeaec95e..5b8d8a6dac 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1098,6 +1099,24 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /*
+ * Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
+ * String)
+ */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Fri_May_24_11_39_19_2024_763)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v20-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v20 4/8] Row pattern recognition patch (planner).
@ 2024-05-24 02:26 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-05-24 02:26 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 24 +++++++++++++++-----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 9 ++++++++
src/include/nodes/plannodes.h | 19 ++++++++++++++++
5 files changed, 76 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 6b64c4a362..ef2101e216 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -287,9 +287,11 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp,
+ List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2700,6 +2702,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
best_path->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6629,8 +6636,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6656,6 +6665,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 032818423f..a5d17e3fda 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -870,6 +870,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root,
EXPRKIND_LIMIT);
wc->endOffset = preprocess_expression(root, wc->endOffset,
EXPRKIND_LIMIT);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 37abcb4701..cd0e7c57d8 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -210,7 +210,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2471,6 +2470,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index 5482ab85a7..f54db3f044 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2175,6 +2175,15 @@ perform_pullup_replace_vars(PlannerInfo *root,
parse->returningList = (List *)
pullup_replace_vars((Node *) parse->returningList, rvcontext);
+ foreach(lc, parse->windowClause)
+ {
+ WindowClause *wc = lfirst_node(WindowClause, lc);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
+ }
+
if (parse->onConflict)
{
parse->onConflict->onConflictSet = (List *)
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 1aeeaec95e..5b8d8a6dac 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1098,6 +1099,24 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /*
+ * Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
+ * String)
+ */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Fri_May_24_11_39_19_2024_763)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v20-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v21 4/8] Row pattern recognition patch (planner).
@ 2024-08-26 04:32 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-08-26 04:32 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 24 +++++++++++++++-----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 9 ++++++++
src/include/nodes/plannodes.h | 19 ++++++++++++++++
5 files changed, 76 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 8e0e5977a9..a1b2c71364 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -288,9 +288,11 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp,
+ List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2697,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
best_path->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6631,8 +6638,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6658,6 +6667,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index b5827d3980..ccb66336a8 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -870,6 +870,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root,
EXPRKIND_LIMIT);
wc->endOffset = preprocess_expression(root, wc->endOffset,
EXPRKIND_LIMIT);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 7aed84584c..7d726729ae 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -210,7 +210,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2471,6 +2470,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index 969e257f70..3cedb5c8e5 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2175,6 +2175,15 @@ perform_pullup_replace_vars(PlannerInfo *root,
parse->returningList = (List *)
pullup_replace_vars((Node *) parse->returningList, rvcontext);
+ foreach(lc, parse->windowClause)
+ {
+ WindowClause *wc = lfirst_node(WindowClause, lc);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
+ }
+
if (parse->onConflict)
{
parse->onConflict->onConflictSet = (List *)
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 62cd6a6666..b7b2ac4aaf 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1099,6 +1100,24 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /*
+ * Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
+ * String)
+ */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Mon_Aug_26_13_39_47_2024_878)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v21-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v21 4/8] Row pattern recognition patch (planner).
@ 2024-08-26 04:32 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-08-26 04:32 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 24 +++++++++++++++-----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 9 ++++++++
src/include/nodes/plannodes.h | 19 ++++++++++++++++
5 files changed, 76 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 8e0e5977a9..a1b2c71364 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -288,9 +288,11 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp,
+ List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2697,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
best_path->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6631,8 +6638,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6658,6 +6667,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index b5827d3980..ccb66336a8 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -870,6 +870,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root,
EXPRKIND_LIMIT);
wc->endOffset = preprocess_expression(root, wc->endOffset,
EXPRKIND_LIMIT);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 7aed84584c..7d726729ae 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -210,7 +210,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2471,6 +2470,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index 969e257f70..3cedb5c8e5 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2175,6 +2175,15 @@ perform_pullup_replace_vars(PlannerInfo *root,
parse->returningList = (List *)
pullup_replace_vars((Node *) parse->returningList, rvcontext);
+ foreach(lc, parse->windowClause)
+ {
+ WindowClause *wc = lfirst_node(WindowClause, lc);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
+ }
+
if (parse->onConflict)
{
parse->onConflict->onConflictSet = (List *)
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 62cd6a6666..b7b2ac4aaf 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1099,6 +1100,24 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /*
+ * Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
+ * String)
+ */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Mon_Aug_26_13_39_47_2024_878)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v21-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v21 4/8] Row pattern recognition patch (planner).
@ 2024-08-26 04:32 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-08-26 04:32 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 24 +++++++++++++++-----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 9 ++++++++
src/include/nodes/plannodes.h | 19 ++++++++++++++++
5 files changed, 76 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 8e0e5977a9..a1b2c71364 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -288,9 +288,11 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp,
+ List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2697,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
best_path->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6631,8 +6638,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6658,6 +6667,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index b5827d3980..ccb66336a8 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -870,6 +870,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root,
EXPRKIND_LIMIT);
wc->endOffset = preprocess_expression(root, wc->endOffset,
EXPRKIND_LIMIT);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 7aed84584c..7d726729ae 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -210,7 +210,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2471,6 +2470,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index 969e257f70..3cedb5c8e5 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2175,6 +2175,15 @@ perform_pullup_replace_vars(PlannerInfo *root,
parse->returningList = (List *)
pullup_replace_vars((Node *) parse->returningList, rvcontext);
+ foreach(lc, parse->windowClause)
+ {
+ WindowClause *wc = lfirst_node(WindowClause, lc);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
+ }
+
if (parse->onConflict)
{
parse->onConflict->onConflictSet = (List *)
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 62cd6a6666..b7b2ac4aaf 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1099,6 +1100,24 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /*
+ * Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
+ * String)
+ */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Mon_Aug_26_13_39_47_2024_878)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v21-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v22 4/8] Row pattern recognition patch (planner).
@ 2024-09-19 04:48 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-09-19 04:48 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 24 +++++++++++++++-----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 9 ++++++++
src/include/nodes/plannodes.h | 19 ++++++++++++++++
5 files changed, 76 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index bb45ef318f..b0adb9cbd8 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -288,9 +288,11 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp,
+ List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2697,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
best_path->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6631,8 +6638,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6658,6 +6667,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index d92d43a17e..771b4b051d 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -879,6 +879,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root,
EXPRKIND_LIMIT);
wc->endOffset = preprocess_expression(root, wc->endOffset,
EXPRKIND_LIMIT);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 91c7c4fe2f..b5310e0d72 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -211,7 +211,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2495,6 +2494,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index a70404558f..d4b08a2e48 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2176,6 +2176,15 @@ perform_pullup_replace_vars(PlannerInfo *root,
parse->returningList = (List *)
pullup_replace_vars((Node *) parse->returningList, rvcontext);
+ foreach(lc, parse->windowClause)
+ {
+ WindowClause *wc = lfirst_node(WindowClause, lc);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
+ }
+
if (parse->onConflict)
{
parse->onConflict->onConflictSet = (List *)
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 62cd6a6666..b7b2ac4aaf 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1099,6 +1100,24 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /*
+ * Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
+ * String)
+ */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Thu_Sep_19_13_59_47_2024_608)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v22-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v22 4/8] Row pattern recognition patch (planner).
@ 2024-09-19 04:48 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-09-19 04:48 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 24 +++++++++++++++-----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 9 ++++++++
src/include/nodes/plannodes.h | 19 ++++++++++++++++
5 files changed, 76 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index bb45ef318f..b0adb9cbd8 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -288,9 +288,11 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp,
+ List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2697,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
best_path->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6631,8 +6638,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6658,6 +6667,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index d92d43a17e..771b4b051d 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -879,6 +879,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root,
EXPRKIND_LIMIT);
wc->endOffset = preprocess_expression(root, wc->endOffset,
EXPRKIND_LIMIT);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 91c7c4fe2f..b5310e0d72 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -211,7 +211,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2495,6 +2494,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index a70404558f..d4b08a2e48 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2176,6 +2176,15 @@ perform_pullup_replace_vars(PlannerInfo *root,
parse->returningList = (List *)
pullup_replace_vars((Node *) parse->returningList, rvcontext);
+ foreach(lc, parse->windowClause)
+ {
+ WindowClause *wc = lfirst_node(WindowClause, lc);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
+ }
+
if (parse->onConflict)
{
parse->onConflict->onConflictSet = (List *)
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 62cd6a6666..b7b2ac4aaf 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1099,6 +1100,24 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /*
+ * Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
+ * String)
+ */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Thu_Sep_19_13_59_47_2024_608)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v22-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v22 4/8] Row pattern recognition patch (planner).
@ 2024-09-19 04:48 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-09-19 04:48 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 24 +++++++++++++++-----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 9 ++++++++
src/include/nodes/plannodes.h | 19 ++++++++++++++++
5 files changed, 76 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index bb45ef318f..b0adb9cbd8 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -288,9 +288,11 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp,
+ List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2697,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
best_path->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6631,8 +6638,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6658,6 +6667,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index d92d43a17e..771b4b051d 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -879,6 +879,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root,
EXPRKIND_LIMIT);
wc->endOffset = preprocess_expression(root, wc->endOffset,
EXPRKIND_LIMIT);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 91c7c4fe2f..b5310e0d72 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -211,7 +211,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2495,6 +2494,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index a70404558f..d4b08a2e48 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2176,6 +2176,15 @@ perform_pullup_replace_vars(PlannerInfo *root,
parse->returningList = (List *)
pullup_replace_vars((Node *) parse->returningList, rvcontext);
+ foreach(lc, parse->windowClause)
+ {
+ WindowClause *wc = lfirst_node(WindowClause, lc);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
+ }
+
if (parse->onConflict)
{
parse->onConflict->onConflictSet = (List *)
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 62cd6a6666..b7b2ac4aaf 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1099,6 +1100,24 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /*
+ * Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
+ * String)
+ */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Thu_Sep_19_13_59_47_2024_608)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v22-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v23 4/8] Row pattern recognition patch (planner).
@ 2024-10-25 03:56 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-10-25 03:56 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 24 +++++++++++++++-----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 9 ++++++++
src/include/nodes/plannodes.h | 19 ++++++++++++++++
5 files changed, 76 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index f2ed0d81f6..1490ded185 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -290,9 +290,11 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp,
+ List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2700,6 +2702,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
best_path->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6706,8 +6713,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6733,6 +6742,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 0f423e9684..24f0744c7c 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -879,6 +879,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root,
EXPRKIND_LIMIT);
wc->endOffset = preprocess_expression(root, wc->endOffset,
EXPRKIND_LIMIT);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 91c7c4fe2f..b5310e0d72 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -211,7 +211,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2495,6 +2494,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index 4d7f972caf..1dcfcf338d 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2271,6 +2271,15 @@ perform_pullup_replace_vars(PlannerInfo *root,
parse->returningList = (List *)
pullup_replace_vars((Node *) parse->returningList, rvcontext);
+ foreach(lc, parse->windowClause)
+ {
+ WindowClause *wc = lfirst_node(WindowClause, lc);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
+ }
+
if (parse->onConflict)
{
parse->onConflict->onConflictSet = (List *)
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 52f29bcdb6..294597461b 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1099,6 +1100,24 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /*
+ * Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
+ * String)
+ */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Fri_Oct_25_13_04_53_2024_648)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v23-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v23 4/8] Row pattern recognition patch (planner).
@ 2024-10-25 03:56 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-10-25 03:56 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 24 +++++++++++++++-----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 9 ++++++++
src/include/nodes/plannodes.h | 19 ++++++++++++++++
5 files changed, 76 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index f2ed0d81f6..1490ded185 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -290,9 +290,11 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp,
+ List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2700,6 +2702,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
best_path->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6706,8 +6713,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6733,6 +6742,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 0f423e9684..24f0744c7c 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -879,6 +879,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root,
EXPRKIND_LIMIT);
wc->endOffset = preprocess_expression(root, wc->endOffset,
EXPRKIND_LIMIT);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 91c7c4fe2f..b5310e0d72 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -211,7 +211,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2495,6 +2494,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index 4d7f972caf..1dcfcf338d 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2271,6 +2271,15 @@ perform_pullup_replace_vars(PlannerInfo *root,
parse->returningList = (List *)
pullup_replace_vars((Node *) parse->returningList, rvcontext);
+ foreach(lc, parse->windowClause)
+ {
+ WindowClause *wc = lfirst_node(WindowClause, lc);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
+ }
+
if (parse->onConflict)
{
parse->onConflict->onConflictSet = (List *)
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 52f29bcdb6..294597461b 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1099,6 +1100,24 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /*
+ * Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
+ * String)
+ */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Fri_Oct_25_13_04_53_2024_648)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v23-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v23 4/8] Row pattern recognition patch (planner).
@ 2024-10-25 03:56 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-10-25 03:56 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 24 +++++++++++++++-----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 9 ++++++++
src/include/nodes/plannodes.h | 19 ++++++++++++++++
5 files changed, 76 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index f2ed0d81f6..1490ded185 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -290,9 +290,11 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp,
+ List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2700,6 +2702,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
best_path->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6706,8 +6713,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6733,6 +6742,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 0f423e9684..24f0744c7c 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -879,6 +879,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root,
EXPRKIND_LIMIT);
wc->endOffset = preprocess_expression(root, wc->endOffset,
EXPRKIND_LIMIT);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 91c7c4fe2f..b5310e0d72 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -211,7 +211,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2495,6 +2494,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index 4d7f972caf..1dcfcf338d 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2271,6 +2271,15 @@ perform_pullup_replace_vars(PlannerInfo *root,
parse->returningList = (List *)
pullup_replace_vars((Node *) parse->returningList, rvcontext);
+ foreach(lc, parse->windowClause)
+ {
+ WindowClause *wc = lfirst_node(WindowClause, lc);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
+ }
+
if (parse->onConflict)
{
parse->onConflict->onConflictSet = (List *)
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 52f29bcdb6..294597461b 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1099,6 +1100,24 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /*
+ * Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
+ * String)
+ */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Fri_Oct_25_13_04_53_2024_648)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v23-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v24 4/8] Row pattern recognition patch (planner).
@ 2024-12-19 06:06 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-12-19 06:06 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 24 +++++++++++++++-----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 9 ++++++++
src/include/nodes/plannodes.h | 19 ++++++++++++++++
5 files changed, 76 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 178c572b02..2aedb43791 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -290,9 +290,11 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp,
+ List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2700,6 +2702,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
best_path->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6704,8 +6711,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6731,6 +6740,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index a0a2de7ee4..e11935aeb8 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -881,6 +881,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root,
EXPRKIND_LIMIT);
wc->endOffset = preprocess_expression(root, wc->endOffset,
EXPRKIND_LIMIT);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 6d23df108d..70c9733e3f 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -211,7 +211,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2492,6 +2491,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index 3fa4d78c3e..3ef9cbff27 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2298,6 +2298,15 @@ perform_pullup_replace_vars(PlannerInfo *root,
parse->returningList = (List *)
pullup_replace_vars((Node *) parse->returningList, rvcontext);
+ foreach(lc, parse->windowClause)
+ {
+ WindowClause *wc = lfirst_node(WindowClause, lc);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
+ }
+
if (parse->onConflict)
{
parse->onConflict->onConflictSet = (List *)
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 52f29bcdb6..294597461b 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1099,6 +1100,24 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /*
+ * Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
+ * String)
+ */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Thu_Dec_19_15_19_50_2024_894)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v24-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v24 4/8] Row pattern recognition patch (planner).
@ 2024-12-19 06:06 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-12-19 06:06 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 24 +++++++++++++++-----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 9 ++++++++
src/include/nodes/plannodes.h | 19 ++++++++++++++++
5 files changed, 76 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 178c572b02..2aedb43791 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -290,9 +290,11 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp,
+ List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2700,6 +2702,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
best_path->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6704,8 +6711,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6731,6 +6740,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index a0a2de7ee4..e11935aeb8 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -881,6 +881,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root,
EXPRKIND_LIMIT);
wc->endOffset = preprocess_expression(root, wc->endOffset,
EXPRKIND_LIMIT);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 6d23df108d..70c9733e3f 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -211,7 +211,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2492,6 +2491,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index 3fa4d78c3e..3ef9cbff27 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2298,6 +2298,15 @@ perform_pullup_replace_vars(PlannerInfo *root,
parse->returningList = (List *)
pullup_replace_vars((Node *) parse->returningList, rvcontext);
+ foreach(lc, parse->windowClause)
+ {
+ WindowClause *wc = lfirst_node(WindowClause, lc);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
+ }
+
if (parse->onConflict)
{
parse->onConflict->onConflictSet = (List *)
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 52f29bcdb6..294597461b 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1099,6 +1100,24 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /*
+ * Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
+ * String)
+ */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Thu_Dec_19_15_19_50_2024_894)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v24-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v24 4/8] Row pattern recognition patch (planner).
@ 2024-12-19 06:06 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-12-19 06:06 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 24 +++++++++++++++-----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 9 ++++++++
src/include/nodes/plannodes.h | 19 ++++++++++++++++
5 files changed, 76 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 178c572b02..2aedb43791 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -290,9 +290,11 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp,
+ List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2700,6 +2702,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
best_path->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6704,8 +6711,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6731,6 +6740,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index a0a2de7ee4..e11935aeb8 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -881,6 +881,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root,
EXPRKIND_LIMIT);
wc->endOffset = preprocess_expression(root, wc->endOffset,
EXPRKIND_LIMIT);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 6d23df108d..70c9733e3f 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -211,7 +211,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2492,6 +2491,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index 3fa4d78c3e..3ef9cbff27 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2298,6 +2298,15 @@ perform_pullup_replace_vars(PlannerInfo *root,
parse->returningList = (List *)
pullup_replace_vars((Node *) parse->returningList, rvcontext);
+ foreach(lc, parse->windowClause)
+ {
+ WindowClause *wc = lfirst_node(WindowClause, lc);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
+ }
+
if (parse->onConflict)
{
parse->onConflict->onConflictSet = (List *)
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 52f29bcdb6..294597461b 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1099,6 +1100,24 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /*
+ * Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
+ * String)
+ */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Thu_Dec_19_15_19_50_2024_894)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v24-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v25 4/9] Row pattern recognition patch (planner).
@ 2024-12-21 06:19 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-12-21 06:19 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 24 +++++++++++++++-----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 9 ++++++++
src/include/nodes/plannodes.h | 19 ++++++++++++++++
5 files changed, 76 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 178c572b02..2aedb43791 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -290,9 +290,11 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp,
+ List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2700,6 +2702,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
best_path->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6704,8 +6711,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6731,6 +6740,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index f3856c519f..11bab38057 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -881,6 +881,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root,
EXPRKIND_LIMIT);
wc->endOffset = preprocess_expression(root, wc->endOffset,
EXPRKIND_LIMIT);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 6d23df108d..70c9733e3f 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -211,7 +211,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2492,6 +2491,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index adad7ea9a9..842738adc9 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2298,6 +2298,15 @@ perform_pullup_replace_vars(PlannerInfo *root,
parse->returningList = (List *)
pullup_replace_vars((Node *) parse->returningList, rvcontext);
+ foreach(lc, parse->windowClause)
+ {
+ WindowClause *wc = lfirst_node(WindowClause, lc);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
+ }
+
if (parse->onConflict)
{
parse->onConflict->onConflictSet = (List *)
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 52f29bcdb6..294597461b 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1099,6 +1100,24 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /*
+ * Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
+ * String)
+ */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Sat_Dec_21_18_20_04_2024_526)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v25-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v25 4/9] Row pattern recognition patch (planner).
@ 2024-12-21 06:19 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-12-21 06:19 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 24 +++++++++++++++-----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 9 ++++++++
src/include/nodes/plannodes.h | 19 ++++++++++++++++
5 files changed, 76 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 178c572b02..2aedb43791 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -290,9 +290,11 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp,
+ List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2700,6 +2702,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
best_path->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6704,8 +6711,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6731,6 +6740,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index f3856c519f..11bab38057 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -881,6 +881,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root,
EXPRKIND_LIMIT);
wc->endOffset = preprocess_expression(root, wc->endOffset,
EXPRKIND_LIMIT);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 6d23df108d..70c9733e3f 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -211,7 +211,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2492,6 +2491,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index adad7ea9a9..842738adc9 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2298,6 +2298,15 @@ perform_pullup_replace_vars(PlannerInfo *root,
parse->returningList = (List *)
pullup_replace_vars((Node *) parse->returningList, rvcontext);
+ foreach(lc, parse->windowClause)
+ {
+ WindowClause *wc = lfirst_node(WindowClause, lc);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
+ }
+
if (parse->onConflict)
{
parse->onConflict->onConflictSet = (List *)
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 52f29bcdb6..294597461b 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1099,6 +1100,24 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /*
+ * Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
+ * String)
+ */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Sat_Dec_21_18_20_04_2024_526)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v25-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v25 4/9] Row pattern recognition patch (planner).
@ 2024-12-21 06:19 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-12-21 06:19 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 24 +++++++++++++++-----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 9 ++++++++
src/include/nodes/plannodes.h | 19 ++++++++++++++++
5 files changed, 76 insertions(+), 6 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 178c572b02..2aedb43791 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -290,9 +290,11 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp,
+ List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2700,6 +2702,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
best_path->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6704,8 +6711,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6731,6 +6740,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index f3856c519f..11bab38057 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -881,6 +881,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root,
EXPRKIND_LIMIT);
wc->endOffset = preprocess_expression(root, wc->endOffset,
EXPRKIND_LIMIT);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 6d23df108d..70c9733e3f 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -211,7 +211,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2492,6 +2491,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index adad7ea9a9..842738adc9 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2298,6 +2298,15 @@ perform_pullup_replace_vars(PlannerInfo *root,
parse->returningList = (List *)
pullup_replace_vars((Node *) parse->returningList, rvcontext);
+ foreach(lc, parse->windowClause)
+ {
+ WindowClause *wc = lfirst_node(WindowClause, lc);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
+ }
+
if (parse->onConflict)
{
parse->onConflict->onConflictSet = (List *)
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 52f29bcdb6..294597461b 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1099,6 +1100,24 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /*
+ * Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
+ * String)
+ */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Sat_Dec_21_18_20_04_2024_526)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v25-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v26 4/9] Row pattern recognition patch (planner).
@ 2024-12-30 12:44 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-12-30 12:44 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 22 ++++++++++++++----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 9 ++++++++
src/include/nodes/plannodes.h | 19 ++++++++++++++++
5 files changed, 75 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index b3e2294e84..e99ac4652e 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -291,8 +291,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ List *runCondition, RPSkipTo rpSkipTo, List *patternVariable,
+ List *patternRegexp, List *defineClause,
+ List *defineInitial, List *qual,
+ bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2700,6 +2702,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
best_path->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6708,8 +6715,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6735,6 +6744,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 7468961b01..f123721e06 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -881,6 +881,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root,
EXPRKIND_LIMIT);
wc->endOffset = preprocess_expression(root, wc->endOffset,
EXPRKIND_LIMIT);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 6d23df108d..70c9733e3f 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -211,7 +211,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2492,6 +2491,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index adad7ea9a9..842738adc9 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2298,6 +2298,15 @@ perform_pullup_replace_vars(PlannerInfo *root,
parse->returningList = (List *)
pullup_replace_vars((Node *) parse->returningList, rvcontext);
+ foreach(lc, parse->windowClause)
+ {
+ WindowClause *wc = lfirst_node(WindowClause, lc);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
+ }
+
if (parse->onConflict)
{
parse->onConflict->onConflictSet = (List *)
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 4633121689..1e7cc2a94e 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1099,6 +1100,24 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /*
+ * Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
+ * String)
+ */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Mon_Dec_30_22_37_18_2024_171)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v26-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v26 4/9] Row pattern recognition patch (planner).
@ 2024-12-30 12:44 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-12-30 12:44 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 22 ++++++++++++++----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 9 ++++++++
src/include/nodes/plannodes.h | 19 ++++++++++++++++
5 files changed, 75 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index b3e2294e84..e99ac4652e 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -291,8 +291,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ List *runCondition, RPSkipTo rpSkipTo, List *patternVariable,
+ List *patternRegexp, List *defineClause,
+ List *defineInitial, List *qual,
+ bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2700,6 +2702,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
best_path->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6708,8 +6715,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6735,6 +6744,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 7468961b01..f123721e06 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -881,6 +881,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root,
EXPRKIND_LIMIT);
wc->endOffset = preprocess_expression(root, wc->endOffset,
EXPRKIND_LIMIT);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 6d23df108d..70c9733e3f 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -211,7 +211,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2492,6 +2491,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index adad7ea9a9..842738adc9 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2298,6 +2298,15 @@ perform_pullup_replace_vars(PlannerInfo *root,
parse->returningList = (List *)
pullup_replace_vars((Node *) parse->returningList, rvcontext);
+ foreach(lc, parse->windowClause)
+ {
+ WindowClause *wc = lfirst_node(WindowClause, lc);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
+ }
+
if (parse->onConflict)
{
parse->onConflict->onConflictSet = (List *)
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 4633121689..1e7cc2a94e 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1099,6 +1100,24 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /*
+ * Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
+ * String)
+ */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Mon_Dec_30_22_37_18_2024_171)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v26-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v26 4/9] Row pattern recognition patch (planner).
@ 2024-12-30 12:44 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-12-30 12:44 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 22 ++++++++++++++----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 9 ++++++++
src/include/nodes/plannodes.h | 19 ++++++++++++++++
5 files changed, 75 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index b3e2294e84..e99ac4652e 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -291,8 +291,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ List *runCondition, RPSkipTo rpSkipTo, List *patternVariable,
+ List *patternRegexp, List *defineClause,
+ List *defineInitial, List *qual,
+ bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2700,6 +2702,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
best_path->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6708,8 +6715,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6735,6 +6744,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 7468961b01..f123721e06 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -881,6 +881,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root,
EXPRKIND_LIMIT);
wc->endOffset = preprocess_expression(root, wc->endOffset,
EXPRKIND_LIMIT);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 6d23df108d..70c9733e3f 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -211,7 +211,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2492,6 +2491,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index adad7ea9a9..842738adc9 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2298,6 +2298,15 @@ perform_pullup_replace_vars(PlannerInfo *root,
parse->returningList = (List *)
pullup_replace_vars((Node *) parse->returningList, rvcontext);
+ foreach(lc, parse->windowClause)
+ {
+ WindowClause *wc = lfirst_node(WindowClause, lc);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
+ }
+
if (parse->onConflict)
{
parse->onConflict->onConflictSet = (List *)
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 4633121689..1e7cc2a94e 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1099,6 +1100,24 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /*
+ * Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
+ * String)
+ */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Mon_Dec_30_22_37_18_2024_171)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v26-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v27 4/9] Row pattern recognition patch (planner).
@ 2024-12-30 23:53 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-12-30 23:53 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 22 ++++++++++++++----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 9 ++++++++
src/include/nodes/plannodes.h | 19 ++++++++++++++++
5 files changed, 75 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index b3e2294e84..e99ac4652e 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -291,8 +291,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ List *runCondition, RPSkipTo rpSkipTo, List *patternVariable,
+ List *patternRegexp, List *defineClause,
+ List *defineInitial, List *qual,
+ bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2700,6 +2702,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
best_path->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6708,8 +6715,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6735,6 +6744,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 7468961b01..f123721e06 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -881,6 +881,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root,
EXPRKIND_LIMIT);
wc->endOffset = preprocess_expression(root, wc->endOffset,
EXPRKIND_LIMIT);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 6d23df108d..70c9733e3f 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -211,7 +211,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2492,6 +2491,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index adad7ea9a9..842738adc9 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2298,6 +2298,15 @@ perform_pullup_replace_vars(PlannerInfo *root,
parse->returningList = (List *)
pullup_replace_vars((Node *) parse->returningList, rvcontext);
+ foreach(lc, parse->windowClause)
+ {
+ WindowClause *wc = lfirst_node(WindowClause, lc);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
+ }
+
if (parse->onConflict)
{
parse->onConflict->onConflictSet = (List *)
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 4633121689..1e7cc2a94e 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1099,6 +1100,24 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /*
+ * Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
+ * String)
+ */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Tue_Dec_31_08_57_07_2024_963)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v27-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v27 4/9] Row pattern recognition patch (planner).
@ 2024-12-30 23:53 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-12-30 23:53 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 22 ++++++++++++++----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 9 ++++++++
src/include/nodes/plannodes.h | 19 ++++++++++++++++
5 files changed, 75 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index b3e2294e84..e99ac4652e 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -291,8 +291,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ List *runCondition, RPSkipTo rpSkipTo, List *patternVariable,
+ List *patternRegexp, List *defineClause,
+ List *defineInitial, List *qual,
+ bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2700,6 +2702,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
best_path->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6708,8 +6715,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6735,6 +6744,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 7468961b01..f123721e06 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -881,6 +881,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root,
EXPRKIND_LIMIT);
wc->endOffset = preprocess_expression(root, wc->endOffset,
EXPRKIND_LIMIT);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 6d23df108d..70c9733e3f 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -211,7 +211,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2492,6 +2491,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index adad7ea9a9..842738adc9 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2298,6 +2298,15 @@ perform_pullup_replace_vars(PlannerInfo *root,
parse->returningList = (List *)
pullup_replace_vars((Node *) parse->returningList, rvcontext);
+ foreach(lc, parse->windowClause)
+ {
+ WindowClause *wc = lfirst_node(WindowClause, lc);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
+ }
+
if (parse->onConflict)
{
parse->onConflict->onConflictSet = (List *)
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 4633121689..1e7cc2a94e 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1099,6 +1100,24 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /*
+ * Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
+ * String)
+ */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Tue_Dec_31_08_57_07_2024_963)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v27-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* [PATCH v27 4/9] Row pattern recognition patch (planner).
@ 2024-12-30 23:53 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Tatsuo Ishii @ 2024-12-30 23:53 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 22 ++++++++++++++----
src/backend/optimizer/plan/planner.c | 3 +++
src/backend/optimizer/plan/setrefs.c | 27 ++++++++++++++++++++++-
src/backend/optimizer/prep/prepjointree.c | 9 ++++++++
src/include/nodes/plannodes.h | 19 ++++++++++++++++
5 files changed, 75 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index b3e2294e84..e99ac4652e 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -291,8 +291,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ List *runCondition, RPSkipTo rpSkipTo, List *patternVariable,
+ List *patternRegexp, List *defineClause,
+ List *defineInitial, List *qual,
+ bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2700,6 +2702,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
best_path->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6708,8 +6715,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6735,6 +6744,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 7468961b01..f123721e06 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -881,6 +881,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root,
EXPRKIND_LIMIT);
wc->endOffset = preprocess_expression(root, wc->endOffset,
EXPRKIND_LIMIT);
+ wc->defineClause = (List *) preprocess_expression(root,
+ (Node *) wc->defineClause,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 6d23df108d..70c9733e3f 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -211,7 +211,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
List *runcondition,
Plan *plan);
-
/*****************************************************************************
*
* SUBPLAN REFERENCES
@@ -2492,6 +2491,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes's varno refers to OUTER_VAR.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ if (wplan->defineClause != NIL)
+ {
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index adad7ea9a9..842738adc9 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2298,6 +2298,15 @@ perform_pullup_replace_vars(PlannerInfo *root,
parse->returningList = (List *)
pullup_replace_vars((Node *) parse->returningList, rvcontext);
+ foreach(lc, parse->windowClause)
+ {
+ WindowClause *wc = lfirst_node(WindowClause, lc);
+
+ if (wc->defineClause != NIL)
+ wc->defineClause = (List *)
+ pullup_replace_vars((Node *) wc->defineClause, rvcontext);
+ }
+
if (parse->onConflict)
{
parse->onConflict->onConflictSet = (List *)
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 4633121689..1e7cc2a94e 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -20,6 +20,7 @@
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
+#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
@@ -1099,6 +1100,24 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /*
+ * Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
+ * String)
+ */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Tue_Dec_31_08_57_07_2024_963)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v27-0005-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 4308+ messages in thread
* teach pg_upgrade to handle in-place tablespaces
@ 2025-04-28 21:07 Nathan Bossart <[email protected]>
2025-04-28 22:01 ` Re: teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
0 siblings, 1 reply; 4308+ messages in thread
From: Nathan Bossart @ 2025-04-28 21:07 UTC (permalink / raw)
To: pgsql-hackers
(Creating new thread from https://postgr.es/m/Z-MaPREQvH5YB0af%40nathan.)
On Tue, Mar 25, 2025 at 04:03:57PM -0500, Nathan Bossart wrote:
> I also wanted to draw attention to this note in 0003:
>
> /*
> * XXX: The below line is a hack to deal with the fact that we
> * presently don't have an easy way to find the corresponding new
> * tablespace's path. This will need to be fixed if/when we add
> * pg_upgrade support for in-place tablespaces.
> */
> new_tablespace = old_tablespace;
>
> I intend to address this in v19, primarily to enable same-version
> pg_upgrade testing with non-default tablespaces. My current thinking is
> that we should have pg_upgrade also gather the new cluster tablespace
> information and map them to the corresponding tablespaces on the old
> cluster. This might require some refactoring in pg_upgrade. In any case,
> I didn't feel this should block the feature for v18.
Patch attached.
--
nathan
From a083c5ff7909fb908468625099665712bfeaf527 Mon Sep 17 00:00:00 2001
From: Nathan Bossart <[email protected]>
Date: Mon, 28 Apr 2025 14:52:11 -0500
Subject: [PATCH v1 1/1] Teach pg_upgrade to handle in-place tablespaces.
Presently, pg_upgrade assumes that all non-default tablespaces
don't move to different directories during upgrade. Unfortunately,
this isn't true for in-place tablespaces, which move to the new
cluster's pg_tblspc directory. This commit teaches pg_upgrade to
handle in-place tablespaces by retrieving the tablespace
directories for both the old and new clusters. In turn, we can
relax the prohibition on non-default tablespaces for same-version
upgrades, i.e., if all non-default tablespaces are in-place,
pg_upgrade may proceed.
This change is primarily intended to enable additional pg_upgrade
testing with non-default tablespaces, as is done in
006_transfer_modes.pl.
---
src/bin/pg_upgrade/check.c | 20 +++----
src/bin/pg_upgrade/info.c | 36 +++++++++++--
src/bin/pg_upgrade/parallel.c | 8 +--
src/bin/pg_upgrade/pg_upgrade.h | 8 +--
src/bin/pg_upgrade/relfilenumber.c | 57 +++++++++-----------
src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 ++++++------
src/bin/pg_upgrade/tablespace.c | 61 +++++++++++++++++-----
7 files changed, 141 insertions(+), 82 deletions(-)
diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c
index 18c2d652bb6..b273ce584cd 100644
--- a/src/bin/pg_upgrade/check.c
+++ b/src/bin/pg_upgrade/check.c
@@ -943,12 +943,12 @@ check_for_new_tablespace_dir(void)
prep_status("Checking for new cluster tablespace directories");
- for (tblnum = 0; tblnum < os_info.num_old_tablespaces; tblnum++)
+ for (tblnum = 0; tblnum < new_cluster.num_tablespaces; tblnum++)
{
struct stat statbuf;
snprintf(new_tablespace_dir, MAXPGPATH, "%s%s",
- os_info.old_tablespaces[tblnum],
+ new_cluster.tablespaces[tblnum],
new_cluster.tablespace_suffix);
if (stat(new_tablespace_dir, &statbuf) == 0 || errno != ENOENT)
@@ -1000,17 +1000,17 @@ create_script_for_old_cluster_deletion(char **deletion_script_file_name)
* directory. We can't create a proper old cluster delete script in that
* case.
*/
- for (tblnum = 0; tblnum < os_info.num_old_tablespaces; tblnum++)
+ for (tblnum = 0; tblnum < new_cluster.num_tablespaces; tblnum++)
{
- char old_tablespace_dir[MAXPGPATH];
+ char new_tablespace_dir[MAXPGPATH];
- strlcpy(old_tablespace_dir, os_info.old_tablespaces[tblnum], MAXPGPATH);
- canonicalize_path(old_tablespace_dir);
- if (path_is_prefix_of_path(old_cluster_pgdata, old_tablespace_dir))
+ strlcpy(new_tablespace_dir, new_cluster.tablespaces[tblnum], MAXPGPATH);
+ canonicalize_path(new_tablespace_dir);
+ if (path_is_prefix_of_path(old_cluster_pgdata, new_tablespace_dir))
{
/* reproduce warning from CREATE TABLESPACE that is in the log */
pg_log(PG_WARNING,
- "\nWARNING: user-defined tablespace locations should not be inside the data directory, i.e. %s", old_tablespace_dir);
+ "\nWARNING: user-defined tablespace locations should not be inside the data directory, i.e. %s", new_tablespace_dir);
/* Unlink file in case it is left over from a previous run. */
unlink(*deletion_script_file_name);
@@ -1038,9 +1038,9 @@ create_script_for_old_cluster_deletion(char **deletion_script_file_name)
/* delete old cluster's alternate tablespaces */
old_tblspc_suffix = pg_strdup(old_cluster.tablespace_suffix);
fix_path_separator(old_tblspc_suffix);
- for (tblnum = 0; tblnum < os_info.num_old_tablespaces; tblnum++)
+ for (tblnum = 0; tblnum < old_cluster.num_tablespaces; tblnum++)
fprintf(script, RMDIR_CMD " %c%s%s%c\n", PATH_QUOTE,
- fix_path_separator(os_info.old_tablespaces[tblnum]),
+ fix_path_separator(old_cluster.tablespaces[tblnum]),
old_tblspc_suffix, PATH_QUOTE);
pfree(old_tblspc_suffix);
diff --git a/src/bin/pg_upgrade/info.c b/src/bin/pg_upgrade/info.c
index 4b7a56f5b3b..00c7187b260 100644
--- a/src/bin/pg_upgrade/info.c
+++ b/src/bin/pg_upgrade/info.c
@@ -443,10 +443,24 @@ get_db_infos(ClusterInfo *cluster)
for (tupnum = 0; tupnum < ntups; tupnum++)
{
+ char *spcloc = PQgetvalue(res, tupnum, i_spclocation);
+ bool inplace = spcloc[0] && !is_absolute_path(spcloc);
+
dbinfos[tupnum].db_oid = atooid(PQgetvalue(res, tupnum, i_oid));
dbinfos[tupnum].db_name = pg_strdup(PQgetvalue(res, tupnum, i_datname));
- snprintf(dbinfos[tupnum].db_tablespace, sizeof(dbinfos[tupnum].db_tablespace), "%s",
- PQgetvalue(res, tupnum, i_spclocation));
+
+ /*
+ * For in-place tablespaces, pg_tablespace_location() returns a path
+ * relative to the data directory.
+ */
+ if (inplace)
+ snprintf(dbinfos[tupnum].db_tablespace,
+ sizeof(dbinfos[tupnum].db_tablespace),
+ "%s/%s", cluster->pgdata, spcloc);
+ else
+ snprintf(dbinfos[tupnum].db_tablespace,
+ sizeof(dbinfos[tupnum].db_tablespace),
+ "%s", spcloc);
}
PQclear(res);
@@ -616,11 +630,21 @@ process_rel_infos(DbInfo *dbinfo, PGresult *res, void *arg)
/* Is the tablespace oid non-default? */
if (atooid(PQgetvalue(res, relnum, i_reltablespace)) != 0)
{
+ char *spcloc = PQgetvalue(res, relnum, i_spclocation);
+ bool inplace = spcloc[0] && !is_absolute_path(spcloc);
+
/*
* The tablespace location might be "", meaning the cluster
- * default location, i.e. pg_default or pg_global.
+ * default location, i.e. pg_default or pg_global. For in-place
+ * tablespaces, pg_tablespace_location() returns a path relative
+ * to the data directory.
*/
- tablespace = PQgetvalue(res, relnum, i_spclocation);
+ if (inplace)
+ tablespace = psprintf("%s/%s",
+ os_info.running_cluster->pgdata,
+ PQgetvalue(res, relnum, i_spclocation));
+ else
+ tablespace = PQgetvalue(res, relnum, i_spclocation);
/* Can we reuse the previous string allocation? */
if (last_tablespace && strcmp(tablespace, last_tablespace) == 0)
@@ -630,6 +654,10 @@ process_rel_infos(DbInfo *dbinfo, PGresult *res, void *arg)
last_tablespace = curr->tablespace = pg_strdup(tablespace);
curr->tblsp_alloc = true;
}
+
+ /* Free palloc'd string for in-place tablespaces. */
+ if (inplace)
+ pfree(tablespace);
}
else
/* A zero reltablespace oid indicates the database tablespace. */
diff --git a/src/bin/pg_upgrade/parallel.c b/src/bin/pg_upgrade/parallel.c
index 056aa2edaee..fa6eff118ec 100644
--- a/src/bin/pg_upgrade/parallel.c
+++ b/src/bin/pg_upgrade/parallel.c
@@ -40,6 +40,7 @@ typedef struct
char *old_pgdata;
char *new_pgdata;
char *old_tablespace;
+ char *new_tablespace;
} transfer_thread_arg;
static exec_thread_arg **exec_thread_args;
@@ -171,7 +172,7 @@ win32_exec_prog(exec_thread_arg *args)
void
parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
char *old_pgdata, char *new_pgdata,
- char *old_tablespace)
+ char *old_tablespace, char *new_tablespace)
{
#ifndef WIN32
pid_t child;
@@ -181,7 +182,7 @@ parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
#endif
if (user_opts.jobs <= 1)
- transfer_all_new_dbs(old_db_arr, new_db_arr, old_pgdata, new_pgdata, NULL);
+ transfer_all_new_dbs(old_db_arr, new_db_arr, old_pgdata, new_pgdata, NULL, NULL);
else
{
/* parallel */
@@ -225,7 +226,7 @@ parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
if (child == 0)
{
transfer_all_new_dbs(old_db_arr, new_db_arr, old_pgdata, new_pgdata,
- old_tablespace);
+ old_tablespace, new_tablespace);
/* if we take another exit path, it will be non-zero */
/* use _exit to skip atexit() functions */
_exit(0);
@@ -246,6 +247,7 @@ parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
new_arg->new_pgdata = pg_strdup(new_pgdata);
pg_free(new_arg->old_tablespace);
new_arg->old_tablespace = old_tablespace ? pg_strdup(old_tablespace) : NULL;
+ new_arg->new_tablespace = new_tablespace ? pg_strdup(new_tablespace) : NULL;
child = (HANDLE) _beginthreadex(NULL, 0, (void *) win32_transfer_all_new_dbs,
new_arg, 0, NULL);
diff --git a/src/bin/pg_upgrade/pg_upgrade.h b/src/bin/pg_upgrade/pg_upgrade.h
index 69c965bb7d0..e56ea7a96f6 100644
--- a/src/bin/pg_upgrade/pg_upgrade.h
+++ b/src/bin/pg_upgrade/pg_upgrade.h
@@ -300,6 +300,8 @@ typedef struct
uint32 major_version; /* PG_VERSION of cluster */
char major_version_str[64]; /* string PG_VERSION of cluster */
uint32 bin_version; /* version returned from pg_ctl */
+ char **tablespaces; /* tablespace directories */
+ int num_tablespaces;
const char *tablespace_suffix; /* directory specification */
int nsubs; /* number of subscriptions */
} ClusterInfo;
@@ -354,8 +356,6 @@ typedef struct
const char *progname; /* complete pathname for this program */
char *user; /* username for clusters */
bool user_specified; /* user specified on command-line */
- char **old_tablespaces; /* tablespaces */
- int num_old_tablespaces;
LibraryInfo *libraries; /* loadable libraries */
int num_libraries;
ClusterInfo *running_cluster;
@@ -455,7 +455,7 @@ void transfer_all_new_tablespaces(DbInfoArr *old_db_arr,
DbInfoArr *new_db_arr, char *old_pgdata, char *new_pgdata);
void transfer_all_new_dbs(DbInfoArr *old_db_arr,
DbInfoArr *new_db_arr, char *old_pgdata, char *new_pgdata,
- char *old_tablespace);
+ char *old_tablespace, char *new_tablespace);
/* tablespace.c */
@@ -503,7 +503,7 @@ void parallel_exec_prog(const char *log_file, const char *opt_log_file,
const char *fmt,...) pg_attribute_printf(3, 4);
void parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
char *old_pgdata, char *new_pgdata,
- char *old_tablespace);
+ char *old_tablespace, char *new_tablespace);
bool reap_child(bool wait_for_child);
/* task.c */
diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c
index 2959c07f0b8..4126653dfff 100644
--- a/src/bin/pg_upgrade/relfilenumber.c
+++ b/src/bin/pg_upgrade/relfilenumber.c
@@ -17,7 +17,7 @@
#include "common/logging.h"
#include "pg_upgrade.h"
-static void transfer_single_new_db(FileNameMap *maps, int size, char *old_tablespace);
+static void transfer_single_new_db(FileNameMap *maps, int size, char *old_tablespace, char *new_tablespace);
static void transfer_relfile(FileNameMap *map, const char *type_suffix, bool vm_must_add_frozenbit);
/*
@@ -136,21 +136,22 @@ transfer_all_new_tablespaces(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
*/
if (user_opts.jobs <= 1)
parallel_transfer_all_new_dbs(old_db_arr, new_db_arr, old_pgdata,
- new_pgdata, NULL);
+ new_pgdata, NULL, NULL);
else
{
int tblnum;
/* transfer default tablespace */
parallel_transfer_all_new_dbs(old_db_arr, new_db_arr, old_pgdata,
- new_pgdata, old_pgdata);
+ new_pgdata, old_pgdata, new_pgdata);
- for (tblnum = 0; tblnum < os_info.num_old_tablespaces; tblnum++)
+ for (tblnum = 0; tblnum < old_cluster.num_tablespaces; tblnum++)
parallel_transfer_all_new_dbs(old_db_arr,
new_db_arr,
old_pgdata,
new_pgdata,
- os_info.old_tablespaces[tblnum]);
+ old_cluster.tablespaces[tblnum],
+ new_cluster.tablespaces[tblnum]);
/* reap all children */
while (reap_child(true) == true)
;
@@ -169,7 +170,8 @@ transfer_all_new_tablespaces(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
*/
void
transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
- char *old_pgdata, char *new_pgdata, char *old_tablespace)
+ char *old_pgdata, char *new_pgdata,
+ char *old_tablespace, char *new_tablespace)
{
int old_dbnum,
new_dbnum;
@@ -204,7 +206,7 @@ transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
new_pgdata);
if (n_maps)
{
- transfer_single_new_db(mappings, n_maps, old_tablespace);
+ transfer_single_new_db(mappings, n_maps, old_tablespace, new_tablespace);
}
/* We allocate something even for n_maps == 0 */
pg_free(mappings);
@@ -234,10 +236,10 @@ transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
* moved_db_dir: Destination for the pg_restore-generated database directory.
*/
static bool
-prepare_for_swap(const char *old_tablespace, Oid db_oid,
- char *old_catalog_dir, char *new_db_dir, char *moved_db_dir)
+prepare_for_swap(const char *old_tablespace, const char *new_tablespace,
+ Oid db_oid, char *old_catalog_dir, char *new_db_dir,
+ char *moved_db_dir)
{
- const char *new_tablespace;
const char *old_tblspc_suffix;
const char *new_tblspc_suffix;
char old_tblspc[MAXPGPATH];
@@ -247,24 +249,14 @@ prepare_for_swap(const char *old_tablespace, Oid db_oid,
struct stat st;
if (strcmp(old_tablespace, old_cluster.pgdata) == 0)
- {
- new_tablespace = new_cluster.pgdata;
- new_tblspc_suffix = "/base";
old_tblspc_suffix = "/base";
- }
else
- {
- /*
- * XXX: The below line is a hack to deal with the fact that we
- * presently don't have an easy way to find the corresponding new
- * tablespace's path. This will need to be fixed if/when we add
- * pg_upgrade support for in-place tablespaces.
- */
- new_tablespace = old_tablespace;
+ old_tblspc_suffix = old_cluster.tablespace_suffix;
+ if (strcmp(new_tablespace, new_cluster.pgdata) == 0)
+ new_tblspc_suffix = "/base";
+ else
new_tblspc_suffix = new_cluster.tablespace_suffix;
- old_tblspc_suffix = old_cluster.tablespace_suffix;
- }
/* Old and new cluster paths. */
snprintf(old_tblspc, sizeof(old_tblspc), "%s%s", old_tablespace, old_tblspc_suffix);
@@ -450,7 +442,7 @@ swap_catalog_files(FileNameMap *maps, int size, const char *old_catalog_dir,
* during pg_restore.
*/
static void
-do_swap(FileNameMap *maps, int size, char *old_tablespace)
+do_swap(FileNameMap *maps, int size, char *old_tablespace, char *new_tablespace)
{
char old_catalog_dir[MAXPGPATH];
char new_db_dir[MAXPGPATH];
@@ -470,21 +462,23 @@ do_swap(FileNameMap *maps, int size, char *old_tablespace)
*/
if (old_tablespace)
{
- if (prepare_for_swap(old_tablespace, maps[0].db_oid,
+ if (prepare_for_swap(old_tablespace, new_tablespace, maps[0].db_oid,
old_catalog_dir, new_db_dir, moved_db_dir))
swap_catalog_files(maps, size,
old_catalog_dir, new_db_dir, moved_db_dir);
}
else
{
- if (prepare_for_swap(old_cluster.pgdata, maps[0].db_oid,
+ if (prepare_for_swap(old_cluster.pgdata, new_cluster.pgdata, maps[0].db_oid,
old_catalog_dir, new_db_dir, moved_db_dir))
swap_catalog_files(maps, size,
old_catalog_dir, new_db_dir, moved_db_dir);
- for (int tblnum = 0; tblnum < os_info.num_old_tablespaces; tblnum++)
+ for (int tblnum = 0; tblnum < old_cluster.num_tablespaces; tblnum++)
{
- if (prepare_for_swap(os_info.old_tablespaces[tblnum], maps[0].db_oid,
+ if (prepare_for_swap(old_cluster.tablespaces[tblnum],
+ new_cluster.tablespaces[tblnum],
+ maps[0].db_oid,
old_catalog_dir, new_db_dir, moved_db_dir))
swap_catalog_files(maps, size,
old_catalog_dir, new_db_dir, moved_db_dir);
@@ -498,7 +492,8 @@ do_swap(FileNameMap *maps, int size, char *old_tablespace)
* create links for mappings stored in "maps" array.
*/
static void
-transfer_single_new_db(FileNameMap *maps, int size, char *old_tablespace)
+transfer_single_new_db(FileNameMap *maps, int size,
+ char *old_tablespace, char *new_tablespace)
{
int mapnum;
bool vm_must_add_frozenbit = false;
@@ -520,7 +515,7 @@ transfer_single_new_db(FileNameMap *maps, int size, char *old_tablespace)
*/
Assert(!vm_must_add_frozenbit);
- do_swap(maps, size, old_tablespace);
+ do_swap(maps, size, old_tablespace, new_tablespace);
return;
}
diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl
index 550a63fdf7d..7302c438b3d 100644
--- a/src/bin/pg_upgrade/t/006_transfer_modes.pl
+++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl
@@ -37,6 +37,12 @@ sub test_mode
}
$new->init();
+ if (!defined($ENV{oldinstall}))
+ {
+ $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true");
+ $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true");
+ }
+
# Create a small variety of simple test objects on the old cluster. We'll
# check that these reach the new version after upgrading.
$old->start;
@@ -46,16 +52,15 @@ sub test_mode
$old->safe_psql('testdb1', "VACUUM FULL test2");
$old->safe_psql('testdb1', "CREATE SEQUENCE testseq START 5432");
- # For cross-version tests, we can also check that pg_upgrade handles
- # tablespaces.
+ my $tblspc = '';
if (defined($ENV{oldinstall}))
{
- my $tblspc = PostgreSQL::Test::Utils::tempdir_short();
- $old->safe_psql('postgres', "CREATE TABLESPACE test_tblspc LOCATION '$tblspc'");
- $old->safe_psql('postgres', "CREATE DATABASE testdb2 TABLESPACE test_tblspc");
- $old->safe_psql('postgres', "CREATE TABLE test3 TABLESPACE test_tblspc AS SELECT generate_series(300, 401)");
- $old->safe_psql('testdb2', "CREATE TABLE test4 AS SELECT generate_series(400, 502)");
+ $tblspc = PostgreSQL::Test::Utils::tempdir_short();
}
+ $old->safe_psql('postgres', "CREATE TABLESPACE test_tblspc LOCATION '$tblspc'");
+ $old->safe_psql('postgres', "CREATE DATABASE testdb2 TABLESPACE test_tblspc");
+ $old->safe_psql('postgres', "CREATE TABLE test3 TABLESPACE test_tblspc AS SELECT generate_series(300, 401)");
+ $old->safe_psql('testdb2', "CREATE TABLE test4 AS SELECT generate_series(400, 502)");
$old->stop;
my $result = command_ok_or_fails_like(
@@ -85,16 +90,10 @@ sub test_mode
is($result, '101', "test2 data after pg_upgrade $mode");
$result = $new->safe_psql('testdb1', "SELECT nextval('testseq')");
is($result, '5432', "sequence data after pg_upgrade $mode");
-
- # For cross-version tests, we should have some objects in a non-default
- # tablespace.
- if (defined($ENV{oldinstall}))
- {
- $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test3");
- is($result, '102', "test3 data after pg_upgrade $mode");
- $result = $new->safe_psql('testdb2', "SELECT COUNT(*) FROM test4");
- is($result, '103', "test4 data after pg_upgrade $mode");
- }
+ $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test3");
+ is($result, '102', "test3 data after pg_upgrade $mode");
+ $result = $new->safe_psql('testdb2', "SELECT COUNT(*) FROM test4");
+ is($result, '103', "test4 data after pg_upgrade $mode");
$new->stop;
}
diff --git a/src/bin/pg_upgrade/tablespace.c b/src/bin/pg_upgrade/tablespace.c
index 3520a75ba31..178fce9fe34 100644
--- a/src/bin/pg_upgrade/tablespace.c
+++ b/src/bin/pg_upgrade/tablespace.c
@@ -23,10 +23,20 @@ init_tablespaces(void)
set_tablespace_directory_suffix(&old_cluster);
set_tablespace_directory_suffix(&new_cluster);
- if (os_info.num_old_tablespaces > 0 &&
+ if (old_cluster.num_tablespaces > 0 &&
strcmp(old_cluster.tablespace_suffix, new_cluster.tablespace_suffix) == 0)
- pg_fatal("Cannot upgrade to/from the same system catalog version when\n"
- "using tablespaces.");
+ {
+ for (int i = 0; i < old_cluster.num_tablespaces; i++)
+ {
+ /*
+ * In-place tablespaces are okay for same-version upgrades because
+ * their paths will differ between clusters.
+ */
+ if (strcmp(old_cluster.tablespaces[i], new_cluster.tablespaces[i]) == 0)
+ pg_fatal("Cannot upgrade to/from the same system catalog version when\n"
+ "using tablespaces.");
+ }
+ }
}
@@ -53,19 +63,44 @@ get_tablespace_paths(void)
res = executeQueryOrDie(conn, "%s", query);
- if ((os_info.num_old_tablespaces = PQntuples(res)) != 0)
- os_info.old_tablespaces =
- (char **) pg_malloc(os_info.num_old_tablespaces * sizeof(char *));
+ old_cluster.num_tablespaces = PQntuples(res);
+ new_cluster.num_tablespaces = PQntuples(res);
+
+ if (PQntuples(res) != 0)
+ {
+ old_cluster.tablespaces =
+ (char **) pg_malloc(old_cluster.num_tablespaces * sizeof(char *));
+ new_cluster.tablespaces =
+ (char **) pg_malloc(new_cluster.num_tablespaces * sizeof(char *));
+ }
else
- os_info.old_tablespaces = NULL;
+ {
+ old_cluster.tablespaces = NULL;
+ new_cluster.tablespaces = NULL;
+ }
i_spclocation = PQfnumber(res, "spclocation");
- for (tblnum = 0; tblnum < os_info.num_old_tablespaces; tblnum++)
+ for (tblnum = 0; tblnum < old_cluster.num_tablespaces; tblnum++)
{
struct stat statBuf;
+ char *spcloc = PQgetvalue(res, tblnum, i_spclocation);
- os_info.old_tablespaces[tblnum] = pg_strdup(PQgetvalue(res, tblnum, i_spclocation));
+ /*
+ * For now, we do not expect non-in-place tablespaces to move during
+ * upgrade. If that changes, it will likely become necessary to run
+ * the above query on the new cluster, too.
+ */
+ if (is_absolute_path(PQgetvalue(res, tblnum, i_spclocation)))
+ {
+ old_cluster.tablespaces[tblnum] = pg_strdup(spcloc);
+ new_cluster.tablespaces[tblnum] = old_cluster.tablespaces[tblnum];
+ }
+ else
+ {
+ old_cluster.tablespaces[tblnum] = psprintf("%s/%s", old_cluster.pgdata, spcloc);
+ new_cluster.tablespaces[tblnum] = psprintf("%s/%s", new_cluster.pgdata, spcloc);
+ }
/*
* Check that the tablespace path exists and is a directory.
@@ -76,21 +111,21 @@ get_tablespace_paths(void)
* that contains user tablespaces is moved as part of pg_upgrade
* preparation and the symbolic links are not updated.
*/
- if (stat(os_info.old_tablespaces[tblnum], &statBuf) != 0)
+ if (stat(old_cluster.tablespaces[tblnum], &statBuf) != 0)
{
if (errno == ENOENT)
report_status(PG_FATAL,
"tablespace directory \"%s\" does not exist",
- os_info.old_tablespaces[tblnum]);
+ old_cluster.tablespaces[tblnum]);
else
report_status(PG_FATAL,
"could not stat tablespace directory \"%s\": %m",
- os_info.old_tablespaces[tblnum]);
+ old_cluster.tablespaces[tblnum]);
}
if (!S_ISDIR(statBuf.st_mode))
report_status(PG_FATAL,
"tablespace path \"%s\" is not a directory",
- os_info.old_tablespaces[tblnum]);
+ old_cluster.tablespaces[tblnum]);
}
PQclear(res);
--
2.39.5 (Apple Git-154)
Attachments:
[text/plain] v1-0001-Teach-pg_upgrade-to-handle-in-place-tablespaces.patch (22.0K, ../../aA_uBLYMUs5D66Nb@nathan/2-v1-0001-Teach-pg_upgrade-to-handle-in-place-tablespaces.patch)
download | inline diff:
From a083c5ff7909fb908468625099665712bfeaf527 Mon Sep 17 00:00:00 2001
From: Nathan Bossart <[email protected]>
Date: Mon, 28 Apr 2025 14:52:11 -0500
Subject: [PATCH v1 1/1] Teach pg_upgrade to handle in-place tablespaces.
Presently, pg_upgrade assumes that all non-default tablespaces
don't move to different directories during upgrade. Unfortunately,
this isn't true for in-place tablespaces, which move to the new
cluster's pg_tblspc directory. This commit teaches pg_upgrade to
handle in-place tablespaces by retrieving the tablespace
directories for both the old and new clusters. In turn, we can
relax the prohibition on non-default tablespaces for same-version
upgrades, i.e., if all non-default tablespaces are in-place,
pg_upgrade may proceed.
This change is primarily intended to enable additional pg_upgrade
testing with non-default tablespaces, as is done in
006_transfer_modes.pl.
---
src/bin/pg_upgrade/check.c | 20 +++----
src/bin/pg_upgrade/info.c | 36 +++++++++++--
src/bin/pg_upgrade/parallel.c | 8 +--
src/bin/pg_upgrade/pg_upgrade.h | 8 +--
src/bin/pg_upgrade/relfilenumber.c | 57 +++++++++-----------
src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 ++++++------
src/bin/pg_upgrade/tablespace.c | 61 +++++++++++++++++-----
7 files changed, 141 insertions(+), 82 deletions(-)
diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c
index 18c2d652bb6..b273ce584cd 100644
--- a/src/bin/pg_upgrade/check.c
+++ b/src/bin/pg_upgrade/check.c
@@ -943,12 +943,12 @@ check_for_new_tablespace_dir(void)
prep_status("Checking for new cluster tablespace directories");
- for (tblnum = 0; tblnum < os_info.num_old_tablespaces; tblnum++)
+ for (tblnum = 0; tblnum < new_cluster.num_tablespaces; tblnum++)
{
struct stat statbuf;
snprintf(new_tablespace_dir, MAXPGPATH, "%s%s",
- os_info.old_tablespaces[tblnum],
+ new_cluster.tablespaces[tblnum],
new_cluster.tablespace_suffix);
if (stat(new_tablespace_dir, &statbuf) == 0 || errno != ENOENT)
@@ -1000,17 +1000,17 @@ create_script_for_old_cluster_deletion(char **deletion_script_file_name)
* directory. We can't create a proper old cluster delete script in that
* case.
*/
- for (tblnum = 0; tblnum < os_info.num_old_tablespaces; tblnum++)
+ for (tblnum = 0; tblnum < new_cluster.num_tablespaces; tblnum++)
{
- char old_tablespace_dir[MAXPGPATH];
+ char new_tablespace_dir[MAXPGPATH];
- strlcpy(old_tablespace_dir, os_info.old_tablespaces[tblnum], MAXPGPATH);
- canonicalize_path(old_tablespace_dir);
- if (path_is_prefix_of_path(old_cluster_pgdata, old_tablespace_dir))
+ strlcpy(new_tablespace_dir, new_cluster.tablespaces[tblnum], MAXPGPATH);
+ canonicalize_path(new_tablespace_dir);
+ if (path_is_prefix_of_path(old_cluster_pgdata, new_tablespace_dir))
{
/* reproduce warning from CREATE TABLESPACE that is in the log */
pg_log(PG_WARNING,
- "\nWARNING: user-defined tablespace locations should not be inside the data directory, i.e. %s", old_tablespace_dir);
+ "\nWARNING: user-defined tablespace locations should not be inside the data directory, i.e. %s", new_tablespace_dir);
/* Unlink file in case it is left over from a previous run. */
unlink(*deletion_script_file_name);
@@ -1038,9 +1038,9 @@ create_script_for_old_cluster_deletion(char **deletion_script_file_name)
/* delete old cluster's alternate tablespaces */
old_tblspc_suffix = pg_strdup(old_cluster.tablespace_suffix);
fix_path_separator(old_tblspc_suffix);
- for (tblnum = 0; tblnum < os_info.num_old_tablespaces; tblnum++)
+ for (tblnum = 0; tblnum < old_cluster.num_tablespaces; tblnum++)
fprintf(script, RMDIR_CMD " %c%s%s%c\n", PATH_QUOTE,
- fix_path_separator(os_info.old_tablespaces[tblnum]),
+ fix_path_separator(old_cluster.tablespaces[tblnum]),
old_tblspc_suffix, PATH_QUOTE);
pfree(old_tblspc_suffix);
diff --git a/src/bin/pg_upgrade/info.c b/src/bin/pg_upgrade/info.c
index 4b7a56f5b3b..00c7187b260 100644
--- a/src/bin/pg_upgrade/info.c
+++ b/src/bin/pg_upgrade/info.c
@@ -443,10 +443,24 @@ get_db_infos(ClusterInfo *cluster)
for (tupnum = 0; tupnum < ntups; tupnum++)
{
+ char *spcloc = PQgetvalue(res, tupnum, i_spclocation);
+ bool inplace = spcloc[0] && !is_absolute_path(spcloc);
+
dbinfos[tupnum].db_oid = atooid(PQgetvalue(res, tupnum, i_oid));
dbinfos[tupnum].db_name = pg_strdup(PQgetvalue(res, tupnum, i_datname));
- snprintf(dbinfos[tupnum].db_tablespace, sizeof(dbinfos[tupnum].db_tablespace), "%s",
- PQgetvalue(res, tupnum, i_spclocation));
+
+ /*
+ * For in-place tablespaces, pg_tablespace_location() returns a path
+ * relative to the data directory.
+ */
+ if (inplace)
+ snprintf(dbinfos[tupnum].db_tablespace,
+ sizeof(dbinfos[tupnum].db_tablespace),
+ "%s/%s", cluster->pgdata, spcloc);
+ else
+ snprintf(dbinfos[tupnum].db_tablespace,
+ sizeof(dbinfos[tupnum].db_tablespace),
+ "%s", spcloc);
}
PQclear(res);
@@ -616,11 +630,21 @@ process_rel_infos(DbInfo *dbinfo, PGresult *res, void *arg)
/* Is the tablespace oid non-default? */
if (atooid(PQgetvalue(res, relnum, i_reltablespace)) != 0)
{
+ char *spcloc = PQgetvalue(res, relnum, i_spclocation);
+ bool inplace = spcloc[0] && !is_absolute_path(spcloc);
+
/*
* The tablespace location might be "", meaning the cluster
- * default location, i.e. pg_default or pg_global.
+ * default location, i.e. pg_default or pg_global. For in-place
+ * tablespaces, pg_tablespace_location() returns a path relative
+ * to the data directory.
*/
- tablespace = PQgetvalue(res, relnum, i_spclocation);
+ if (inplace)
+ tablespace = psprintf("%s/%s",
+ os_info.running_cluster->pgdata,
+ PQgetvalue(res, relnum, i_spclocation));
+ else
+ tablespace = PQgetvalue(res, relnum, i_spclocation);
/* Can we reuse the previous string allocation? */
if (last_tablespace && strcmp(tablespace, last_tablespace) == 0)
@@ -630,6 +654,10 @@ process_rel_infos(DbInfo *dbinfo, PGresult *res, void *arg)
last_tablespace = curr->tablespace = pg_strdup(tablespace);
curr->tblsp_alloc = true;
}
+
+ /* Free palloc'd string for in-place tablespaces. */
+ if (inplace)
+ pfree(tablespace);
}
else
/* A zero reltablespace oid indicates the database tablespace. */
diff --git a/src/bin/pg_upgrade/parallel.c b/src/bin/pg_upgrade/parallel.c
index 056aa2edaee..fa6eff118ec 100644
--- a/src/bin/pg_upgrade/parallel.c
+++ b/src/bin/pg_upgrade/parallel.c
@@ -40,6 +40,7 @@ typedef struct
char *old_pgdata;
char *new_pgdata;
char *old_tablespace;
+ char *new_tablespace;
} transfer_thread_arg;
static exec_thread_arg **exec_thread_args;
@@ -171,7 +172,7 @@ win32_exec_prog(exec_thread_arg *args)
void
parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
char *old_pgdata, char *new_pgdata,
- char *old_tablespace)
+ char *old_tablespace, char *new_tablespace)
{
#ifndef WIN32
pid_t child;
@@ -181,7 +182,7 @@ parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
#endif
if (user_opts.jobs <= 1)
- transfer_all_new_dbs(old_db_arr, new_db_arr, old_pgdata, new_pgdata, NULL);
+ transfer_all_new_dbs(old_db_arr, new_db_arr, old_pgdata, new_pgdata, NULL, NULL);
else
{
/* parallel */
@@ -225,7 +226,7 @@ parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
if (child == 0)
{
transfer_all_new_dbs(old_db_arr, new_db_arr, old_pgdata, new_pgdata,
- old_tablespace);
+ old_tablespace, new_tablespace);
/* if we take another exit path, it will be non-zero */
/* use _exit to skip atexit() functions */
_exit(0);
@@ -246,6 +247,7 @@ parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
new_arg->new_pgdata = pg_strdup(new_pgdata);
pg_free(new_arg->old_tablespace);
new_arg->old_tablespace = old_tablespace ? pg_strdup(old_tablespace) : NULL;
+ new_arg->new_tablespace = new_tablespace ? pg_strdup(new_tablespace) : NULL;
child = (HANDLE) _beginthreadex(NULL, 0, (void *) win32_transfer_all_new_dbs,
new_arg, 0, NULL);
diff --git a/src/bin/pg_upgrade/pg_upgrade.h b/src/bin/pg_upgrade/pg_upgrade.h
index 69c965bb7d0..e56ea7a96f6 100644
--- a/src/bin/pg_upgrade/pg_upgrade.h
+++ b/src/bin/pg_upgrade/pg_upgrade.h
@@ -300,6 +300,8 @@ typedef struct
uint32 major_version; /* PG_VERSION of cluster */
char major_version_str[64]; /* string PG_VERSION of cluster */
uint32 bin_version; /* version returned from pg_ctl */
+ char **tablespaces; /* tablespace directories */
+ int num_tablespaces;
const char *tablespace_suffix; /* directory specification */
int nsubs; /* number of subscriptions */
} ClusterInfo;
@@ -354,8 +356,6 @@ typedef struct
const char *progname; /* complete pathname for this program */
char *user; /* username for clusters */
bool user_specified; /* user specified on command-line */
- char **old_tablespaces; /* tablespaces */
- int num_old_tablespaces;
LibraryInfo *libraries; /* loadable libraries */
int num_libraries;
ClusterInfo *running_cluster;
@@ -455,7 +455,7 @@ void transfer_all_new_tablespaces(DbInfoArr *old_db_arr,
DbInfoArr *new_db_arr, char *old_pgdata, char *new_pgdata);
void transfer_all_new_dbs(DbInfoArr *old_db_arr,
DbInfoArr *new_db_arr, char *old_pgdata, char *new_pgdata,
- char *old_tablespace);
+ char *old_tablespace, char *new_tablespace);
/* tablespace.c */
@@ -503,7 +503,7 @@ void parallel_exec_prog(const char *log_file, const char *opt_log_file,
const char *fmt,...) pg_attribute_printf(3, 4);
void parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
char *old_pgdata, char *new_pgdata,
- char *old_tablespace);
+ char *old_tablespace, char *new_tablespace);
bool reap_child(bool wait_for_child);
/* task.c */
diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c
index 2959c07f0b8..4126653dfff 100644
--- a/src/bin/pg_upgrade/relfilenumber.c
+++ b/src/bin/pg_upgrade/relfilenumber.c
@@ -17,7 +17,7 @@
#include "common/logging.h"
#include "pg_upgrade.h"
-static void transfer_single_new_db(FileNameMap *maps, int size, char *old_tablespace);
+static void transfer_single_new_db(FileNameMap *maps, int size, char *old_tablespace, char *new_tablespace);
static void transfer_relfile(FileNameMap *map, const char *type_suffix, bool vm_must_add_frozenbit);
/*
@@ -136,21 +136,22 @@ transfer_all_new_tablespaces(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
*/
if (user_opts.jobs <= 1)
parallel_transfer_all_new_dbs(old_db_arr, new_db_arr, old_pgdata,
- new_pgdata, NULL);
+ new_pgdata, NULL, NULL);
else
{
int tblnum;
/* transfer default tablespace */
parallel_transfer_all_new_dbs(old_db_arr, new_db_arr, old_pgdata,
- new_pgdata, old_pgdata);
+ new_pgdata, old_pgdata, new_pgdata);
- for (tblnum = 0; tblnum < os_info.num_old_tablespaces; tblnum++)
+ for (tblnum = 0; tblnum < old_cluster.num_tablespaces; tblnum++)
parallel_transfer_all_new_dbs(old_db_arr,
new_db_arr,
old_pgdata,
new_pgdata,
- os_info.old_tablespaces[tblnum]);
+ old_cluster.tablespaces[tblnum],
+ new_cluster.tablespaces[tblnum]);
/* reap all children */
while (reap_child(true) == true)
;
@@ -169,7 +170,8 @@ transfer_all_new_tablespaces(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
*/
void
transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
- char *old_pgdata, char *new_pgdata, char *old_tablespace)
+ char *old_pgdata, char *new_pgdata,
+ char *old_tablespace, char *new_tablespace)
{
int old_dbnum,
new_dbnum;
@@ -204,7 +206,7 @@ transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
new_pgdata);
if (n_maps)
{
- transfer_single_new_db(mappings, n_maps, old_tablespace);
+ transfer_single_new_db(mappings, n_maps, old_tablespace, new_tablespace);
}
/* We allocate something even for n_maps == 0 */
pg_free(mappings);
@@ -234,10 +236,10 @@ transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
* moved_db_dir: Destination for the pg_restore-generated database directory.
*/
static bool
-prepare_for_swap(const char *old_tablespace, Oid db_oid,
- char *old_catalog_dir, char *new_db_dir, char *moved_db_dir)
+prepare_for_swap(const char *old_tablespace, const char *new_tablespace,
+ Oid db_oid, char *old_catalog_dir, char *new_db_dir,
+ char *moved_db_dir)
{
- const char *new_tablespace;
const char *old_tblspc_suffix;
const char *new_tblspc_suffix;
char old_tblspc[MAXPGPATH];
@@ -247,24 +249,14 @@ prepare_for_swap(const char *old_tablespace, Oid db_oid,
struct stat st;
if (strcmp(old_tablespace, old_cluster.pgdata) == 0)
- {
- new_tablespace = new_cluster.pgdata;
- new_tblspc_suffix = "/base";
old_tblspc_suffix = "/base";
- }
else
- {
- /*
- * XXX: The below line is a hack to deal with the fact that we
- * presently don't have an easy way to find the corresponding new
- * tablespace's path. This will need to be fixed if/when we add
- * pg_upgrade support for in-place tablespaces.
- */
- new_tablespace = old_tablespace;
+ old_tblspc_suffix = old_cluster.tablespace_suffix;
+ if (strcmp(new_tablespace, new_cluster.pgdata) == 0)
+ new_tblspc_suffix = "/base";
+ else
new_tblspc_suffix = new_cluster.tablespace_suffix;
- old_tblspc_suffix = old_cluster.tablespace_suffix;
- }
/* Old and new cluster paths. */
snprintf(old_tblspc, sizeof(old_tblspc), "%s%s", old_tablespace, old_tblspc_suffix);
@@ -450,7 +442,7 @@ swap_catalog_files(FileNameMap *maps, int size, const char *old_catalog_dir,
* during pg_restore.
*/
static void
-do_swap(FileNameMap *maps, int size, char *old_tablespace)
+do_swap(FileNameMap *maps, int size, char *old_tablespace, char *new_tablespace)
{
char old_catalog_dir[MAXPGPATH];
char new_db_dir[MAXPGPATH];
@@ -470,21 +462,23 @@ do_swap(FileNameMap *maps, int size, char *old_tablespace)
*/
if (old_tablespace)
{
- if (prepare_for_swap(old_tablespace, maps[0].db_oid,
+ if (prepare_for_swap(old_tablespace, new_tablespace, maps[0].db_oid,
old_catalog_dir, new_db_dir, moved_db_dir))
swap_catalog_files(maps, size,
old_catalog_dir, new_db_dir, moved_db_dir);
}
else
{
- if (prepare_for_swap(old_cluster.pgdata, maps[0].db_oid,
+ if (prepare_for_swap(old_cluster.pgdata, new_cluster.pgdata, maps[0].db_oid,
old_catalog_dir, new_db_dir, moved_db_dir))
swap_catalog_files(maps, size,
old_catalog_dir, new_db_dir, moved_db_dir);
- for (int tblnum = 0; tblnum < os_info.num_old_tablespaces; tblnum++)
+ for (int tblnum = 0; tblnum < old_cluster.num_tablespaces; tblnum++)
{
- if (prepare_for_swap(os_info.old_tablespaces[tblnum], maps[0].db_oid,
+ if (prepare_for_swap(old_cluster.tablespaces[tblnum],
+ new_cluster.tablespaces[tblnum],
+ maps[0].db_oid,
old_catalog_dir, new_db_dir, moved_db_dir))
swap_catalog_files(maps, size,
old_catalog_dir, new_db_dir, moved_db_dir);
@@ -498,7 +492,8 @@ do_swap(FileNameMap *maps, int size, char *old_tablespace)
* create links for mappings stored in "maps" array.
*/
static void
-transfer_single_new_db(FileNameMap *maps, int size, char *old_tablespace)
+transfer_single_new_db(FileNameMap *maps, int size,
+ char *old_tablespace, char *new_tablespace)
{
int mapnum;
bool vm_must_add_frozenbit = false;
@@ -520,7 +515,7 @@ transfer_single_new_db(FileNameMap *maps, int size, char *old_tablespace)
*/
Assert(!vm_must_add_frozenbit);
- do_swap(maps, size, old_tablespace);
+ do_swap(maps, size, old_tablespace, new_tablespace);
return;
}
diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl
index 550a63fdf7d..7302c438b3d 100644
--- a/src/bin/pg_upgrade/t/006_transfer_modes.pl
+++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl
@@ -37,6 +37,12 @@ sub test_mode
}
$new->init();
+ if (!defined($ENV{oldinstall}))
+ {
+ $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true");
+ $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true");
+ }
+
# Create a small variety of simple test objects on the old cluster. We'll
# check that these reach the new version after upgrading.
$old->start;
@@ -46,16 +52,15 @@ sub test_mode
$old->safe_psql('testdb1', "VACUUM FULL test2");
$old->safe_psql('testdb1', "CREATE SEQUENCE testseq START 5432");
- # For cross-version tests, we can also check that pg_upgrade handles
- # tablespaces.
+ my $tblspc = '';
if (defined($ENV{oldinstall}))
{
- my $tblspc = PostgreSQL::Test::Utils::tempdir_short();
- $old->safe_psql('postgres', "CREATE TABLESPACE test_tblspc LOCATION '$tblspc'");
- $old->safe_psql('postgres', "CREATE DATABASE testdb2 TABLESPACE test_tblspc");
- $old->safe_psql('postgres', "CREATE TABLE test3 TABLESPACE test_tblspc AS SELECT generate_series(300, 401)");
- $old->safe_psql('testdb2', "CREATE TABLE test4 AS SELECT generate_series(400, 502)");
+ $tblspc = PostgreSQL::Test::Utils::tempdir_short();
}
+ $old->safe_psql('postgres', "CREATE TABLESPACE test_tblspc LOCATION '$tblspc'");
+ $old->safe_psql('postgres', "CREATE DATABASE testdb2 TABLESPACE test_tblspc");
+ $old->safe_psql('postgres', "CREATE TABLE test3 TABLESPACE test_tblspc AS SELECT generate_series(300, 401)");
+ $old->safe_psql('testdb2', "CREATE TABLE test4 AS SELECT generate_series(400, 502)");
$old->stop;
my $result = command_ok_or_fails_like(
@@ -85,16 +90,10 @@ sub test_mode
is($result, '101', "test2 data after pg_upgrade $mode");
$result = $new->safe_psql('testdb1', "SELECT nextval('testseq')");
is($result, '5432', "sequence data after pg_upgrade $mode");
-
- # For cross-version tests, we should have some objects in a non-default
- # tablespace.
- if (defined($ENV{oldinstall}))
- {
- $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test3");
- is($result, '102', "test3 data after pg_upgrade $mode");
- $result = $new->safe_psql('testdb2', "SELECT COUNT(*) FROM test4");
- is($result, '103', "test4 data after pg_upgrade $mode");
- }
+ $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test3");
+ is($result, '102', "test3 data after pg_upgrade $mode");
+ $result = $new->safe_psql('testdb2', "SELECT COUNT(*) FROM test4");
+ is($result, '103', "test4 data after pg_upgrade $mode");
$new->stop;
}
diff --git a/src/bin/pg_upgrade/tablespace.c b/src/bin/pg_upgrade/tablespace.c
index 3520a75ba31..178fce9fe34 100644
--- a/src/bin/pg_upgrade/tablespace.c
+++ b/src/bin/pg_upgrade/tablespace.c
@@ -23,10 +23,20 @@ init_tablespaces(void)
set_tablespace_directory_suffix(&old_cluster);
set_tablespace_directory_suffix(&new_cluster);
- if (os_info.num_old_tablespaces > 0 &&
+ if (old_cluster.num_tablespaces > 0 &&
strcmp(old_cluster.tablespace_suffix, new_cluster.tablespace_suffix) == 0)
- pg_fatal("Cannot upgrade to/from the same system catalog version when\n"
- "using tablespaces.");
+ {
+ for (int i = 0; i < old_cluster.num_tablespaces; i++)
+ {
+ /*
+ * In-place tablespaces are okay for same-version upgrades because
+ * their paths will differ between clusters.
+ */
+ if (strcmp(old_cluster.tablespaces[i], new_cluster.tablespaces[i]) == 0)
+ pg_fatal("Cannot upgrade to/from the same system catalog version when\n"
+ "using tablespaces.");
+ }
+ }
}
@@ -53,19 +63,44 @@ get_tablespace_paths(void)
res = executeQueryOrDie(conn, "%s", query);
- if ((os_info.num_old_tablespaces = PQntuples(res)) != 0)
- os_info.old_tablespaces =
- (char **) pg_malloc(os_info.num_old_tablespaces * sizeof(char *));
+ old_cluster.num_tablespaces = PQntuples(res);
+ new_cluster.num_tablespaces = PQntuples(res);
+
+ if (PQntuples(res) != 0)
+ {
+ old_cluster.tablespaces =
+ (char **) pg_malloc(old_cluster.num_tablespaces * sizeof(char *));
+ new_cluster.tablespaces =
+ (char **) pg_malloc(new_cluster.num_tablespaces * sizeof(char *));
+ }
else
- os_info.old_tablespaces = NULL;
+ {
+ old_cluster.tablespaces = NULL;
+ new_cluster.tablespaces = NULL;
+ }
i_spclocation = PQfnumber(res, "spclocation");
- for (tblnum = 0; tblnum < os_info.num_old_tablespaces; tblnum++)
+ for (tblnum = 0; tblnum < old_cluster.num_tablespaces; tblnum++)
{
struct stat statBuf;
+ char *spcloc = PQgetvalue(res, tblnum, i_spclocation);
- os_info.old_tablespaces[tblnum] = pg_strdup(PQgetvalue(res, tblnum, i_spclocation));
+ /*
+ * For now, we do not expect non-in-place tablespaces to move during
+ * upgrade. If that changes, it will likely become necessary to run
+ * the above query on the new cluster, too.
+ */
+ if (is_absolute_path(PQgetvalue(res, tblnum, i_spclocation)))
+ {
+ old_cluster.tablespaces[tblnum] = pg_strdup(spcloc);
+ new_cluster.tablespaces[tblnum] = old_cluster.tablespaces[tblnum];
+ }
+ else
+ {
+ old_cluster.tablespaces[tblnum] = psprintf("%s/%s", old_cluster.pgdata, spcloc);
+ new_cluster.tablespaces[tblnum] = psprintf("%s/%s", new_cluster.pgdata, spcloc);
+ }
/*
* Check that the tablespace path exists and is a directory.
@@ -76,21 +111,21 @@ get_tablespace_paths(void)
* that contains user tablespaces is moved as part of pg_upgrade
* preparation and the symbolic links are not updated.
*/
- if (stat(os_info.old_tablespaces[tblnum], &statBuf) != 0)
+ if (stat(old_cluster.tablespaces[tblnum], &statBuf) != 0)
{
if (errno == ENOENT)
report_status(PG_FATAL,
"tablespace directory \"%s\" does not exist",
- os_info.old_tablespaces[tblnum]);
+ old_cluster.tablespaces[tblnum]);
else
report_status(PG_FATAL,
"could not stat tablespace directory \"%s\": %m",
- os_info.old_tablespaces[tblnum]);
+ old_cluster.tablespaces[tblnum]);
}
if (!S_ISDIR(statBuf.st_mode))
report_status(PG_FATAL,
"tablespace path \"%s\" is not a directory",
- os_info.old_tablespaces[tblnum]);
+ old_cluster.tablespaces[tblnum]);
}
PQclear(res);
--
2.39.5 (Apple Git-154)
^ permalink raw reply [nested|flat] 4308+ messages in thread
* Re: teach pg_upgrade to handle in-place tablespaces
2025-04-28 21:07 teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
@ 2025-04-28 22:01 ` Nathan Bossart <[email protected]>
2025-07-01 20:06 ` Re: teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
0 siblings, 1 reply; 4308+ messages in thread
From: Nathan Bossart @ 2025-04-28 22:01 UTC (permalink / raw)
To: pgsql-hackers
On Mon, Apr 28, 2025 at 04:07:16PM -0500, Nathan Bossart wrote:
> On Tue, Mar 25, 2025 at 04:03:57PM -0500, Nathan Bossart wrote:
>> I also wanted to draw attention to this note in 0003:
>>
>> /*
>> * XXX: The below line is a hack to deal with the fact that we
>> * presently don't have an easy way to find the corresponding new
>> * tablespace's path. This will need to be fixed if/when we add
>> * pg_upgrade support for in-place tablespaces.
>> */
>> new_tablespace = old_tablespace;
>>
>> I intend to address this in v19, primarily to enable same-version
>> pg_upgrade testing with non-default tablespaces. My current thinking is
>> that we should have pg_upgrade also gather the new cluster tablespace
>> information and map them to the corresponding tablespaces on the old
>> cluster. This might require some refactoring in pg_upgrade. In any case,
>> I didn't feel this should block the feature for v18.
>
> Patch attached.
And here is a new version of the patch that should hopefully build on
Windows.
--
nathan
From c34cdd22795b2fca1b60e8fa9b2526fb7d30833a Mon Sep 17 00:00:00 2001
From: Nathan Bossart <[email protected]>
Date: Mon, 28 Apr 2025 14:52:11 -0500
Subject: [PATCH v2 1/1] Teach pg_upgrade to handle in-place tablespaces.
Presently, pg_upgrade assumes that all non-default tablespaces
don't move to different directories during upgrade. Unfortunately,
this isn't true for in-place tablespaces, which move to the new
cluster's pg_tblspc directory. This commit teaches pg_upgrade to
handle in-place tablespaces by retrieving the tablespace
directories for both the old and new clusters. In turn, we can
relax the prohibition on non-default tablespaces for same-version
upgrades, i.e., if all non-default tablespaces are in-place,
pg_upgrade may proceed.
This change is primarily intended to enable additional pg_upgrade
testing with non-default tablespaces, as is done in
006_transfer_modes.pl.
---
src/bin/pg_upgrade/check.c | 20 +++----
src/bin/pg_upgrade/info.c | 36 +++++++++++--
src/bin/pg_upgrade/parallel.c | 11 ++--
src/bin/pg_upgrade/pg_upgrade.h | 8 +--
src/bin/pg_upgrade/relfilenumber.c | 57 +++++++++-----------
src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 ++++++------
src/bin/pg_upgrade/tablespace.c | 61 +++++++++++++++++-----
7 files changed, 143 insertions(+), 83 deletions(-)
diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c
index 18c2d652bb6..b273ce584cd 100644
--- a/src/bin/pg_upgrade/check.c
+++ b/src/bin/pg_upgrade/check.c
@@ -943,12 +943,12 @@ check_for_new_tablespace_dir(void)
prep_status("Checking for new cluster tablespace directories");
- for (tblnum = 0; tblnum < os_info.num_old_tablespaces; tblnum++)
+ for (tblnum = 0; tblnum < new_cluster.num_tablespaces; tblnum++)
{
struct stat statbuf;
snprintf(new_tablespace_dir, MAXPGPATH, "%s%s",
- os_info.old_tablespaces[tblnum],
+ new_cluster.tablespaces[tblnum],
new_cluster.tablespace_suffix);
if (stat(new_tablespace_dir, &statbuf) == 0 || errno != ENOENT)
@@ -1000,17 +1000,17 @@ create_script_for_old_cluster_deletion(char **deletion_script_file_name)
* directory. We can't create a proper old cluster delete script in that
* case.
*/
- for (tblnum = 0; tblnum < os_info.num_old_tablespaces; tblnum++)
+ for (tblnum = 0; tblnum < new_cluster.num_tablespaces; tblnum++)
{
- char old_tablespace_dir[MAXPGPATH];
+ char new_tablespace_dir[MAXPGPATH];
- strlcpy(old_tablespace_dir, os_info.old_tablespaces[tblnum], MAXPGPATH);
- canonicalize_path(old_tablespace_dir);
- if (path_is_prefix_of_path(old_cluster_pgdata, old_tablespace_dir))
+ strlcpy(new_tablespace_dir, new_cluster.tablespaces[tblnum], MAXPGPATH);
+ canonicalize_path(new_tablespace_dir);
+ if (path_is_prefix_of_path(old_cluster_pgdata, new_tablespace_dir))
{
/* reproduce warning from CREATE TABLESPACE that is in the log */
pg_log(PG_WARNING,
- "\nWARNING: user-defined tablespace locations should not be inside the data directory, i.e. %s", old_tablespace_dir);
+ "\nWARNING: user-defined tablespace locations should not be inside the data directory, i.e. %s", new_tablespace_dir);
/* Unlink file in case it is left over from a previous run. */
unlink(*deletion_script_file_name);
@@ -1038,9 +1038,9 @@ create_script_for_old_cluster_deletion(char **deletion_script_file_name)
/* delete old cluster's alternate tablespaces */
old_tblspc_suffix = pg_strdup(old_cluster.tablespace_suffix);
fix_path_separator(old_tblspc_suffix);
- for (tblnum = 0; tblnum < os_info.num_old_tablespaces; tblnum++)
+ for (tblnum = 0; tblnum < old_cluster.num_tablespaces; tblnum++)
fprintf(script, RMDIR_CMD " %c%s%s%c\n", PATH_QUOTE,
- fix_path_separator(os_info.old_tablespaces[tblnum]),
+ fix_path_separator(old_cluster.tablespaces[tblnum]),
old_tblspc_suffix, PATH_QUOTE);
pfree(old_tblspc_suffix);
diff --git a/src/bin/pg_upgrade/info.c b/src/bin/pg_upgrade/info.c
index 4b7a56f5b3b..00c7187b260 100644
--- a/src/bin/pg_upgrade/info.c
+++ b/src/bin/pg_upgrade/info.c
@@ -443,10 +443,24 @@ get_db_infos(ClusterInfo *cluster)
for (tupnum = 0; tupnum < ntups; tupnum++)
{
+ char *spcloc = PQgetvalue(res, tupnum, i_spclocation);
+ bool inplace = spcloc[0] && !is_absolute_path(spcloc);
+
dbinfos[tupnum].db_oid = atooid(PQgetvalue(res, tupnum, i_oid));
dbinfos[tupnum].db_name = pg_strdup(PQgetvalue(res, tupnum, i_datname));
- snprintf(dbinfos[tupnum].db_tablespace, sizeof(dbinfos[tupnum].db_tablespace), "%s",
- PQgetvalue(res, tupnum, i_spclocation));
+
+ /*
+ * For in-place tablespaces, pg_tablespace_location() returns a path
+ * relative to the data directory.
+ */
+ if (inplace)
+ snprintf(dbinfos[tupnum].db_tablespace,
+ sizeof(dbinfos[tupnum].db_tablespace),
+ "%s/%s", cluster->pgdata, spcloc);
+ else
+ snprintf(dbinfos[tupnum].db_tablespace,
+ sizeof(dbinfos[tupnum].db_tablespace),
+ "%s", spcloc);
}
PQclear(res);
@@ -616,11 +630,21 @@ process_rel_infos(DbInfo *dbinfo, PGresult *res, void *arg)
/* Is the tablespace oid non-default? */
if (atooid(PQgetvalue(res, relnum, i_reltablespace)) != 0)
{
+ char *spcloc = PQgetvalue(res, relnum, i_spclocation);
+ bool inplace = spcloc[0] && !is_absolute_path(spcloc);
+
/*
* The tablespace location might be "", meaning the cluster
- * default location, i.e. pg_default or pg_global.
+ * default location, i.e. pg_default or pg_global. For in-place
+ * tablespaces, pg_tablespace_location() returns a path relative
+ * to the data directory.
*/
- tablespace = PQgetvalue(res, relnum, i_spclocation);
+ if (inplace)
+ tablespace = psprintf("%s/%s",
+ os_info.running_cluster->pgdata,
+ PQgetvalue(res, relnum, i_spclocation));
+ else
+ tablespace = PQgetvalue(res, relnum, i_spclocation);
/* Can we reuse the previous string allocation? */
if (last_tablespace && strcmp(tablespace, last_tablespace) == 0)
@@ -630,6 +654,10 @@ process_rel_infos(DbInfo *dbinfo, PGresult *res, void *arg)
last_tablespace = curr->tablespace = pg_strdup(tablespace);
curr->tblsp_alloc = true;
}
+
+ /* Free palloc'd string for in-place tablespaces. */
+ if (inplace)
+ pfree(tablespace);
}
else
/* A zero reltablespace oid indicates the database tablespace. */
diff --git a/src/bin/pg_upgrade/parallel.c b/src/bin/pg_upgrade/parallel.c
index 056aa2edaee..6d7941844a7 100644
--- a/src/bin/pg_upgrade/parallel.c
+++ b/src/bin/pg_upgrade/parallel.c
@@ -40,6 +40,7 @@ typedef struct
char *old_pgdata;
char *new_pgdata;
char *old_tablespace;
+ char *new_tablespace;
} transfer_thread_arg;
static exec_thread_arg **exec_thread_args;
@@ -171,7 +172,7 @@ win32_exec_prog(exec_thread_arg *args)
void
parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
char *old_pgdata, char *new_pgdata,
- char *old_tablespace)
+ char *old_tablespace, char *new_tablespace)
{
#ifndef WIN32
pid_t child;
@@ -181,7 +182,7 @@ parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
#endif
if (user_opts.jobs <= 1)
- transfer_all_new_dbs(old_db_arr, new_db_arr, old_pgdata, new_pgdata, NULL);
+ transfer_all_new_dbs(old_db_arr, new_db_arr, old_pgdata, new_pgdata, NULL, NULL);
else
{
/* parallel */
@@ -225,7 +226,7 @@ parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
if (child == 0)
{
transfer_all_new_dbs(old_db_arr, new_db_arr, old_pgdata, new_pgdata,
- old_tablespace);
+ old_tablespace, new_tablespace);
/* if we take another exit path, it will be non-zero */
/* use _exit to skip atexit() functions */
_exit(0);
@@ -246,6 +247,7 @@ parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
new_arg->new_pgdata = pg_strdup(new_pgdata);
pg_free(new_arg->old_tablespace);
new_arg->old_tablespace = old_tablespace ? pg_strdup(old_tablespace) : NULL;
+ new_arg->new_tablespace = new_tablespace ? pg_strdup(new_tablespace) : NULL;
child = (HANDLE) _beginthreadex(NULL, 0, (void *) win32_transfer_all_new_dbs,
new_arg, 0, NULL);
@@ -263,7 +265,8 @@ DWORD
win32_transfer_all_new_dbs(transfer_thread_arg *args)
{
transfer_all_new_dbs(args->old_db_arr, args->new_db_arr, args->old_pgdata,
- args->new_pgdata, args->old_tablespace);
+ args->new_pgdata, args->old_tablespace,
+ args->new_tablespace);
/* terminates thread */
return 0;
diff --git a/src/bin/pg_upgrade/pg_upgrade.h b/src/bin/pg_upgrade/pg_upgrade.h
index 69c965bb7d0..e56ea7a96f6 100644
--- a/src/bin/pg_upgrade/pg_upgrade.h
+++ b/src/bin/pg_upgrade/pg_upgrade.h
@@ -300,6 +300,8 @@ typedef struct
uint32 major_version; /* PG_VERSION of cluster */
char major_version_str[64]; /* string PG_VERSION of cluster */
uint32 bin_version; /* version returned from pg_ctl */
+ char **tablespaces; /* tablespace directories */
+ int num_tablespaces;
const char *tablespace_suffix; /* directory specification */
int nsubs; /* number of subscriptions */
} ClusterInfo;
@@ -354,8 +356,6 @@ typedef struct
const char *progname; /* complete pathname for this program */
char *user; /* username for clusters */
bool user_specified; /* user specified on command-line */
- char **old_tablespaces; /* tablespaces */
- int num_old_tablespaces;
LibraryInfo *libraries; /* loadable libraries */
int num_libraries;
ClusterInfo *running_cluster;
@@ -455,7 +455,7 @@ void transfer_all_new_tablespaces(DbInfoArr *old_db_arr,
DbInfoArr *new_db_arr, char *old_pgdata, char *new_pgdata);
void transfer_all_new_dbs(DbInfoArr *old_db_arr,
DbInfoArr *new_db_arr, char *old_pgdata, char *new_pgdata,
- char *old_tablespace);
+ char *old_tablespace, char *new_tablespace);
/* tablespace.c */
@@ -503,7 +503,7 @@ void parallel_exec_prog(const char *log_file, const char *opt_log_file,
const char *fmt,...) pg_attribute_printf(3, 4);
void parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
char *old_pgdata, char *new_pgdata,
- char *old_tablespace);
+ char *old_tablespace, char *new_tablespace);
bool reap_child(bool wait_for_child);
/* task.c */
diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c
index 2959c07f0b8..4126653dfff 100644
--- a/src/bin/pg_upgrade/relfilenumber.c
+++ b/src/bin/pg_upgrade/relfilenumber.c
@@ -17,7 +17,7 @@
#include "common/logging.h"
#include "pg_upgrade.h"
-static void transfer_single_new_db(FileNameMap *maps, int size, char *old_tablespace);
+static void transfer_single_new_db(FileNameMap *maps, int size, char *old_tablespace, char *new_tablespace);
static void transfer_relfile(FileNameMap *map, const char *type_suffix, bool vm_must_add_frozenbit);
/*
@@ -136,21 +136,22 @@ transfer_all_new_tablespaces(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
*/
if (user_opts.jobs <= 1)
parallel_transfer_all_new_dbs(old_db_arr, new_db_arr, old_pgdata,
- new_pgdata, NULL);
+ new_pgdata, NULL, NULL);
else
{
int tblnum;
/* transfer default tablespace */
parallel_transfer_all_new_dbs(old_db_arr, new_db_arr, old_pgdata,
- new_pgdata, old_pgdata);
+ new_pgdata, old_pgdata, new_pgdata);
- for (tblnum = 0; tblnum < os_info.num_old_tablespaces; tblnum++)
+ for (tblnum = 0; tblnum < old_cluster.num_tablespaces; tblnum++)
parallel_transfer_all_new_dbs(old_db_arr,
new_db_arr,
old_pgdata,
new_pgdata,
- os_info.old_tablespaces[tblnum]);
+ old_cluster.tablespaces[tblnum],
+ new_cluster.tablespaces[tblnum]);
/* reap all children */
while (reap_child(true) == true)
;
@@ -169,7 +170,8 @@ transfer_all_new_tablespaces(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
*/
void
transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
- char *old_pgdata, char *new_pgdata, char *old_tablespace)
+ char *old_pgdata, char *new_pgdata,
+ char *old_tablespace, char *new_tablespace)
{
int old_dbnum,
new_dbnum;
@@ -204,7 +206,7 @@ transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
new_pgdata);
if (n_maps)
{
- transfer_single_new_db(mappings, n_maps, old_tablespace);
+ transfer_single_new_db(mappings, n_maps, old_tablespace, new_tablespace);
}
/* We allocate something even for n_maps == 0 */
pg_free(mappings);
@@ -234,10 +236,10 @@ transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
* moved_db_dir: Destination for the pg_restore-generated database directory.
*/
static bool
-prepare_for_swap(const char *old_tablespace, Oid db_oid,
- char *old_catalog_dir, char *new_db_dir, char *moved_db_dir)
+prepare_for_swap(const char *old_tablespace, const char *new_tablespace,
+ Oid db_oid, char *old_catalog_dir, char *new_db_dir,
+ char *moved_db_dir)
{
- const char *new_tablespace;
const char *old_tblspc_suffix;
const char *new_tblspc_suffix;
char old_tblspc[MAXPGPATH];
@@ -247,24 +249,14 @@ prepare_for_swap(const char *old_tablespace, Oid db_oid,
struct stat st;
if (strcmp(old_tablespace, old_cluster.pgdata) == 0)
- {
- new_tablespace = new_cluster.pgdata;
- new_tblspc_suffix = "/base";
old_tblspc_suffix = "/base";
- }
else
- {
- /*
- * XXX: The below line is a hack to deal with the fact that we
- * presently don't have an easy way to find the corresponding new
- * tablespace's path. This will need to be fixed if/when we add
- * pg_upgrade support for in-place tablespaces.
- */
- new_tablespace = old_tablespace;
+ old_tblspc_suffix = old_cluster.tablespace_suffix;
+ if (strcmp(new_tablespace, new_cluster.pgdata) == 0)
+ new_tblspc_suffix = "/base";
+ else
new_tblspc_suffix = new_cluster.tablespace_suffix;
- old_tblspc_suffix = old_cluster.tablespace_suffix;
- }
/* Old and new cluster paths. */
snprintf(old_tblspc, sizeof(old_tblspc), "%s%s", old_tablespace, old_tblspc_suffix);
@@ -450,7 +442,7 @@ swap_catalog_files(FileNameMap *maps, int size, const char *old_catalog_dir,
* during pg_restore.
*/
static void
-do_swap(FileNameMap *maps, int size, char *old_tablespace)
+do_swap(FileNameMap *maps, int size, char *old_tablespace, char *new_tablespace)
{
char old_catalog_dir[MAXPGPATH];
char new_db_dir[MAXPGPATH];
@@ -470,21 +462,23 @@ do_swap(FileNameMap *maps, int size, char *old_tablespace)
*/
if (old_tablespace)
{
- if (prepare_for_swap(old_tablespace, maps[0].db_oid,
+ if (prepare_for_swap(old_tablespace, new_tablespace, maps[0].db_oid,
old_catalog_dir, new_db_dir, moved_db_dir))
swap_catalog_files(maps, size,
old_catalog_dir, new_db_dir, moved_db_dir);
}
else
{
- if (prepare_for_swap(old_cluster.pgdata, maps[0].db_oid,
+ if (prepare_for_swap(old_cluster.pgdata, new_cluster.pgdata, maps[0].db_oid,
old_catalog_dir, new_db_dir, moved_db_dir))
swap_catalog_files(maps, size,
old_catalog_dir, new_db_dir, moved_db_dir);
- for (int tblnum = 0; tblnum < os_info.num_old_tablespaces; tblnum++)
+ for (int tblnum = 0; tblnum < old_cluster.num_tablespaces; tblnum++)
{
- if (prepare_for_swap(os_info.old_tablespaces[tblnum], maps[0].db_oid,
+ if (prepare_for_swap(old_cluster.tablespaces[tblnum],
+ new_cluster.tablespaces[tblnum],
+ maps[0].db_oid,
old_catalog_dir, new_db_dir, moved_db_dir))
swap_catalog_files(maps, size,
old_catalog_dir, new_db_dir, moved_db_dir);
@@ -498,7 +492,8 @@ do_swap(FileNameMap *maps, int size, char *old_tablespace)
* create links for mappings stored in "maps" array.
*/
static void
-transfer_single_new_db(FileNameMap *maps, int size, char *old_tablespace)
+transfer_single_new_db(FileNameMap *maps, int size,
+ char *old_tablespace, char *new_tablespace)
{
int mapnum;
bool vm_must_add_frozenbit = false;
@@ -520,7 +515,7 @@ transfer_single_new_db(FileNameMap *maps, int size, char *old_tablespace)
*/
Assert(!vm_must_add_frozenbit);
- do_swap(maps, size, old_tablespace);
+ do_swap(maps, size, old_tablespace, new_tablespace);
return;
}
diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl
index 550a63fdf7d..7302c438b3d 100644
--- a/src/bin/pg_upgrade/t/006_transfer_modes.pl
+++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl
@@ -37,6 +37,12 @@ sub test_mode
}
$new->init();
+ if (!defined($ENV{oldinstall}))
+ {
+ $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true");
+ $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true");
+ }
+
# Create a small variety of simple test objects on the old cluster. We'll
# check that these reach the new version after upgrading.
$old->start;
@@ -46,16 +52,15 @@ sub test_mode
$old->safe_psql('testdb1', "VACUUM FULL test2");
$old->safe_psql('testdb1', "CREATE SEQUENCE testseq START 5432");
- # For cross-version tests, we can also check that pg_upgrade handles
- # tablespaces.
+ my $tblspc = '';
if (defined($ENV{oldinstall}))
{
- my $tblspc = PostgreSQL::Test::Utils::tempdir_short();
- $old->safe_psql('postgres', "CREATE TABLESPACE test_tblspc LOCATION '$tblspc'");
- $old->safe_psql('postgres', "CREATE DATABASE testdb2 TABLESPACE test_tblspc");
- $old->safe_psql('postgres', "CREATE TABLE test3 TABLESPACE test_tblspc AS SELECT generate_series(300, 401)");
- $old->safe_psql('testdb2', "CREATE TABLE test4 AS SELECT generate_series(400, 502)");
+ $tblspc = PostgreSQL::Test::Utils::tempdir_short();
}
+ $old->safe_psql('postgres', "CREATE TABLESPACE test_tblspc LOCATION '$tblspc'");
+ $old->safe_psql('postgres', "CREATE DATABASE testdb2 TABLESPACE test_tblspc");
+ $old->safe_psql('postgres', "CREATE TABLE test3 TABLESPACE test_tblspc AS SELECT generate_series(300, 401)");
+ $old->safe_psql('testdb2', "CREATE TABLE test4 AS SELECT generate_series(400, 502)");
$old->stop;
my $result = command_ok_or_fails_like(
@@ -85,16 +90,10 @@ sub test_mode
is($result, '101', "test2 data after pg_upgrade $mode");
$result = $new->safe_psql('testdb1', "SELECT nextval('testseq')");
is($result, '5432', "sequence data after pg_upgrade $mode");
-
- # For cross-version tests, we should have some objects in a non-default
- # tablespace.
- if (defined($ENV{oldinstall}))
- {
- $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test3");
- is($result, '102', "test3 data after pg_upgrade $mode");
- $result = $new->safe_psql('testdb2', "SELECT COUNT(*) FROM test4");
- is($result, '103', "test4 data after pg_upgrade $mode");
- }
+ $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test3");
+ is($result, '102', "test3 data after pg_upgrade $mode");
+ $result = $new->safe_psql('testdb2', "SELECT COUNT(*) FROM test4");
+ is($result, '103', "test4 data after pg_upgrade $mode");
$new->stop;
}
diff --git a/src/bin/pg_upgrade/tablespace.c b/src/bin/pg_upgrade/tablespace.c
index 3520a75ba31..178fce9fe34 100644
--- a/src/bin/pg_upgrade/tablespace.c
+++ b/src/bin/pg_upgrade/tablespace.c
@@ -23,10 +23,20 @@ init_tablespaces(void)
set_tablespace_directory_suffix(&old_cluster);
set_tablespace_directory_suffix(&new_cluster);
- if (os_info.num_old_tablespaces > 0 &&
+ if (old_cluster.num_tablespaces > 0 &&
strcmp(old_cluster.tablespace_suffix, new_cluster.tablespace_suffix) == 0)
- pg_fatal("Cannot upgrade to/from the same system catalog version when\n"
- "using tablespaces.");
+ {
+ for (int i = 0; i < old_cluster.num_tablespaces; i++)
+ {
+ /*
+ * In-place tablespaces are okay for same-version upgrades because
+ * their paths will differ between clusters.
+ */
+ if (strcmp(old_cluster.tablespaces[i], new_cluster.tablespaces[i]) == 0)
+ pg_fatal("Cannot upgrade to/from the same system catalog version when\n"
+ "using tablespaces.");
+ }
+ }
}
@@ -53,19 +63,44 @@ get_tablespace_paths(void)
res = executeQueryOrDie(conn, "%s", query);
- if ((os_info.num_old_tablespaces = PQntuples(res)) != 0)
- os_info.old_tablespaces =
- (char **) pg_malloc(os_info.num_old_tablespaces * sizeof(char *));
+ old_cluster.num_tablespaces = PQntuples(res);
+ new_cluster.num_tablespaces = PQntuples(res);
+
+ if (PQntuples(res) != 0)
+ {
+ old_cluster.tablespaces =
+ (char **) pg_malloc(old_cluster.num_tablespaces * sizeof(char *));
+ new_cluster.tablespaces =
+ (char **) pg_malloc(new_cluster.num_tablespaces * sizeof(char *));
+ }
else
- os_info.old_tablespaces = NULL;
+ {
+ old_cluster.tablespaces = NULL;
+ new_cluster.tablespaces = NULL;
+ }
i_spclocation = PQfnumber(res, "spclocation");
- for (tblnum = 0; tblnum < os_info.num_old_tablespaces; tblnum++)
+ for (tblnum = 0; tblnum < old_cluster.num_tablespaces; tblnum++)
{
struct stat statBuf;
+ char *spcloc = PQgetvalue(res, tblnum, i_spclocation);
- os_info.old_tablespaces[tblnum] = pg_strdup(PQgetvalue(res, tblnum, i_spclocation));
+ /*
+ * For now, we do not expect non-in-place tablespaces to move during
+ * upgrade. If that changes, it will likely become necessary to run
+ * the above query on the new cluster, too.
+ */
+ if (is_absolute_path(PQgetvalue(res, tblnum, i_spclocation)))
+ {
+ old_cluster.tablespaces[tblnum] = pg_strdup(spcloc);
+ new_cluster.tablespaces[tblnum] = old_cluster.tablespaces[tblnum];
+ }
+ else
+ {
+ old_cluster.tablespaces[tblnum] = psprintf("%s/%s", old_cluster.pgdata, spcloc);
+ new_cluster.tablespaces[tblnum] = psprintf("%s/%s", new_cluster.pgdata, spcloc);
+ }
/*
* Check that the tablespace path exists and is a directory.
@@ -76,21 +111,21 @@ get_tablespace_paths(void)
* that contains user tablespaces is moved as part of pg_upgrade
* preparation and the symbolic links are not updated.
*/
- if (stat(os_info.old_tablespaces[tblnum], &statBuf) != 0)
+ if (stat(old_cluster.tablespaces[tblnum], &statBuf) != 0)
{
if (errno == ENOENT)
report_status(PG_FATAL,
"tablespace directory \"%s\" does not exist",
- os_info.old_tablespaces[tblnum]);
+ old_cluster.tablespaces[tblnum]);
else
report_status(PG_FATAL,
"could not stat tablespace directory \"%s\": %m",
- os_info.old_tablespaces[tblnum]);
+ old_cluster.tablespaces[tblnum]);
}
if (!S_ISDIR(statBuf.st_mode))
report_status(PG_FATAL,
"tablespace path \"%s\" is not a directory",
- os_info.old_tablespaces[tblnum]);
+ old_cluster.tablespaces[tblnum]);
}
PQclear(res);
--
2.39.5 (Apple Git-154)
Attachments:
[text/plain] v2-0001-Teach-pg_upgrade-to-handle-in-place-tablespaces.patch (22.4K, ../../aA_6wKsPgqfbEypy@nathan/2-v2-0001-Teach-pg_upgrade-to-handle-in-place-tablespaces.patch)
download | inline diff:
From c34cdd22795b2fca1b60e8fa9b2526fb7d30833a Mon Sep 17 00:00:00 2001
From: Nathan Bossart <[email protected]>
Date: Mon, 28 Apr 2025 14:52:11 -0500
Subject: [PATCH v2 1/1] Teach pg_upgrade to handle in-place tablespaces.
Presently, pg_upgrade assumes that all non-default tablespaces
don't move to different directories during upgrade. Unfortunately,
this isn't true for in-place tablespaces, which move to the new
cluster's pg_tblspc directory. This commit teaches pg_upgrade to
handle in-place tablespaces by retrieving the tablespace
directories for both the old and new clusters. In turn, we can
relax the prohibition on non-default tablespaces for same-version
upgrades, i.e., if all non-default tablespaces are in-place,
pg_upgrade may proceed.
This change is primarily intended to enable additional pg_upgrade
testing with non-default tablespaces, as is done in
006_transfer_modes.pl.
---
src/bin/pg_upgrade/check.c | 20 +++----
src/bin/pg_upgrade/info.c | 36 +++++++++++--
src/bin/pg_upgrade/parallel.c | 11 ++--
src/bin/pg_upgrade/pg_upgrade.h | 8 +--
src/bin/pg_upgrade/relfilenumber.c | 57 +++++++++-----------
src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 ++++++------
src/bin/pg_upgrade/tablespace.c | 61 +++++++++++++++++-----
7 files changed, 143 insertions(+), 83 deletions(-)
diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c
index 18c2d652bb6..b273ce584cd 100644
--- a/src/bin/pg_upgrade/check.c
+++ b/src/bin/pg_upgrade/check.c
@@ -943,12 +943,12 @@ check_for_new_tablespace_dir(void)
prep_status("Checking for new cluster tablespace directories");
- for (tblnum = 0; tblnum < os_info.num_old_tablespaces; tblnum++)
+ for (tblnum = 0; tblnum < new_cluster.num_tablespaces; tblnum++)
{
struct stat statbuf;
snprintf(new_tablespace_dir, MAXPGPATH, "%s%s",
- os_info.old_tablespaces[tblnum],
+ new_cluster.tablespaces[tblnum],
new_cluster.tablespace_suffix);
if (stat(new_tablespace_dir, &statbuf) == 0 || errno != ENOENT)
@@ -1000,17 +1000,17 @@ create_script_for_old_cluster_deletion(char **deletion_script_file_name)
* directory. We can't create a proper old cluster delete script in that
* case.
*/
- for (tblnum = 0; tblnum < os_info.num_old_tablespaces; tblnum++)
+ for (tblnum = 0; tblnum < new_cluster.num_tablespaces; tblnum++)
{
- char old_tablespace_dir[MAXPGPATH];
+ char new_tablespace_dir[MAXPGPATH];
- strlcpy(old_tablespace_dir, os_info.old_tablespaces[tblnum], MAXPGPATH);
- canonicalize_path(old_tablespace_dir);
- if (path_is_prefix_of_path(old_cluster_pgdata, old_tablespace_dir))
+ strlcpy(new_tablespace_dir, new_cluster.tablespaces[tblnum], MAXPGPATH);
+ canonicalize_path(new_tablespace_dir);
+ if (path_is_prefix_of_path(old_cluster_pgdata, new_tablespace_dir))
{
/* reproduce warning from CREATE TABLESPACE that is in the log */
pg_log(PG_WARNING,
- "\nWARNING: user-defined tablespace locations should not be inside the data directory, i.e. %s", old_tablespace_dir);
+ "\nWARNING: user-defined tablespace locations should not be inside the data directory, i.e. %s", new_tablespace_dir);
/* Unlink file in case it is left over from a previous run. */
unlink(*deletion_script_file_name);
@@ -1038,9 +1038,9 @@ create_script_for_old_cluster_deletion(char **deletion_script_file_name)
/* delete old cluster's alternate tablespaces */
old_tblspc_suffix = pg_strdup(old_cluster.tablespace_suffix);
fix_path_separator(old_tblspc_suffix);
- for (tblnum = 0; tblnum < os_info.num_old_tablespaces; tblnum++)
+ for (tblnum = 0; tblnum < old_cluster.num_tablespaces; tblnum++)
fprintf(script, RMDIR_CMD " %c%s%s%c\n", PATH_QUOTE,
- fix_path_separator(os_info.old_tablespaces[tblnum]),
+ fix_path_separator(old_cluster.tablespaces[tblnum]),
old_tblspc_suffix, PATH_QUOTE);
pfree(old_tblspc_suffix);
diff --git a/src/bin/pg_upgrade/info.c b/src/bin/pg_upgrade/info.c
index 4b7a56f5b3b..00c7187b260 100644
--- a/src/bin/pg_upgrade/info.c
+++ b/src/bin/pg_upgrade/info.c
@@ -443,10 +443,24 @@ get_db_infos(ClusterInfo *cluster)
for (tupnum = 0; tupnum < ntups; tupnum++)
{
+ char *spcloc = PQgetvalue(res, tupnum, i_spclocation);
+ bool inplace = spcloc[0] && !is_absolute_path(spcloc);
+
dbinfos[tupnum].db_oid = atooid(PQgetvalue(res, tupnum, i_oid));
dbinfos[tupnum].db_name = pg_strdup(PQgetvalue(res, tupnum, i_datname));
- snprintf(dbinfos[tupnum].db_tablespace, sizeof(dbinfos[tupnum].db_tablespace), "%s",
- PQgetvalue(res, tupnum, i_spclocation));
+
+ /*
+ * For in-place tablespaces, pg_tablespace_location() returns a path
+ * relative to the data directory.
+ */
+ if (inplace)
+ snprintf(dbinfos[tupnum].db_tablespace,
+ sizeof(dbinfos[tupnum].db_tablespace),
+ "%s/%s", cluster->pgdata, spcloc);
+ else
+ snprintf(dbinfos[tupnum].db_tablespace,
+ sizeof(dbinfos[tupnum].db_tablespace),
+ "%s", spcloc);
}
PQclear(res);
@@ -616,11 +630,21 @@ process_rel_infos(DbInfo *dbinfo, PGresult *res, void *arg)
/* Is the tablespace oid non-default? */
if (atooid(PQgetvalue(res, relnum, i_reltablespace)) != 0)
{
+ char *spcloc = PQgetvalue(res, relnum, i_spclocation);
+ bool inplace = spcloc[0] && !is_absolute_path(spcloc);
+
/*
* The tablespace location might be "", meaning the cluster
- * default location, i.e. pg_default or pg_global.
+ * default location, i.e. pg_default or pg_global. For in-place
+ * tablespaces, pg_tablespace_location() returns a path relative
+ * to the data directory.
*/
- tablespace = PQgetvalue(res, relnum, i_spclocation);
+ if (inplace)
+ tablespace = psprintf("%s/%s",
+ os_info.running_cluster->pgdata,
+ PQgetvalue(res, relnum, i_spclocation));
+ else
+ tablespace = PQgetvalue(res, relnum, i_spclocation);
/* Can we reuse the previous string allocation? */
if (last_tablespace && strcmp(tablespace, last_tablespace) == 0)
@@ -630,6 +654,10 @@ process_rel_infos(DbInfo *dbinfo, PGresult *res, void *arg)
last_tablespace = curr->tablespace = pg_strdup(tablespace);
curr->tblsp_alloc = true;
}
+
+ /* Free palloc'd string for in-place tablespaces. */
+ if (inplace)
+ pfree(tablespace);
}
else
/* A zero reltablespace oid indicates the database tablespace. */
diff --git a/src/bin/pg_upgrade/parallel.c b/src/bin/pg_upgrade/parallel.c
index 056aa2edaee..6d7941844a7 100644
--- a/src/bin/pg_upgrade/parallel.c
+++ b/src/bin/pg_upgrade/parallel.c
@@ -40,6 +40,7 @@ typedef struct
char *old_pgdata;
char *new_pgdata;
char *old_tablespace;
+ char *new_tablespace;
} transfer_thread_arg;
static exec_thread_arg **exec_thread_args;
@@ -171,7 +172,7 @@ win32_exec_prog(exec_thread_arg *args)
void
parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
char *old_pgdata, char *new_pgdata,
- char *old_tablespace)
+ char *old_tablespace, char *new_tablespace)
{
#ifndef WIN32
pid_t child;
@@ -181,7 +182,7 @@ parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
#endif
if (user_opts.jobs <= 1)
- transfer_all_new_dbs(old_db_arr, new_db_arr, old_pgdata, new_pgdata, NULL);
+ transfer_all_new_dbs(old_db_arr, new_db_arr, old_pgdata, new_pgdata, NULL, NULL);
else
{
/* parallel */
@@ -225,7 +226,7 @@ parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
if (child == 0)
{
transfer_all_new_dbs(old_db_arr, new_db_arr, old_pgdata, new_pgdata,
- old_tablespace);
+ old_tablespace, new_tablespace);
/* if we take another exit path, it will be non-zero */
/* use _exit to skip atexit() functions */
_exit(0);
@@ -246,6 +247,7 @@ parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
new_arg->new_pgdata = pg_strdup(new_pgdata);
pg_free(new_arg->old_tablespace);
new_arg->old_tablespace = old_tablespace ? pg_strdup(old_tablespace) : NULL;
+ new_arg->new_tablespace = new_tablespace ? pg_strdup(new_tablespace) : NULL;
child = (HANDLE) _beginthreadex(NULL, 0, (void *) win32_transfer_all_new_dbs,
new_arg, 0, NULL);
@@ -263,7 +265,8 @@ DWORD
win32_transfer_all_new_dbs(transfer_thread_arg *args)
{
transfer_all_new_dbs(args->old_db_arr, args->new_db_arr, args->old_pgdata,
- args->new_pgdata, args->old_tablespace);
+ args->new_pgdata, args->old_tablespace,
+ args->new_tablespace);
/* terminates thread */
return 0;
diff --git a/src/bin/pg_upgrade/pg_upgrade.h b/src/bin/pg_upgrade/pg_upgrade.h
index 69c965bb7d0..e56ea7a96f6 100644
--- a/src/bin/pg_upgrade/pg_upgrade.h
+++ b/src/bin/pg_upgrade/pg_upgrade.h
@@ -300,6 +300,8 @@ typedef struct
uint32 major_version; /* PG_VERSION of cluster */
char major_version_str[64]; /* string PG_VERSION of cluster */
uint32 bin_version; /* version returned from pg_ctl */
+ char **tablespaces; /* tablespace directories */
+ int num_tablespaces;
const char *tablespace_suffix; /* directory specification */
int nsubs; /* number of subscriptions */
} ClusterInfo;
@@ -354,8 +356,6 @@ typedef struct
const char *progname; /* complete pathname for this program */
char *user; /* username for clusters */
bool user_specified; /* user specified on command-line */
- char **old_tablespaces; /* tablespaces */
- int num_old_tablespaces;
LibraryInfo *libraries; /* loadable libraries */
int num_libraries;
ClusterInfo *running_cluster;
@@ -455,7 +455,7 @@ void transfer_all_new_tablespaces(DbInfoArr *old_db_arr,
DbInfoArr *new_db_arr, char *old_pgdata, char *new_pgdata);
void transfer_all_new_dbs(DbInfoArr *old_db_arr,
DbInfoArr *new_db_arr, char *old_pgdata, char *new_pgdata,
- char *old_tablespace);
+ char *old_tablespace, char *new_tablespace);
/* tablespace.c */
@@ -503,7 +503,7 @@ void parallel_exec_prog(const char *log_file, const char *opt_log_file,
const char *fmt,...) pg_attribute_printf(3, 4);
void parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
char *old_pgdata, char *new_pgdata,
- char *old_tablespace);
+ char *old_tablespace, char *new_tablespace);
bool reap_child(bool wait_for_child);
/* task.c */
diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c
index 2959c07f0b8..4126653dfff 100644
--- a/src/bin/pg_upgrade/relfilenumber.c
+++ b/src/bin/pg_upgrade/relfilenumber.c
@@ -17,7 +17,7 @@
#include "common/logging.h"
#include "pg_upgrade.h"
-static void transfer_single_new_db(FileNameMap *maps, int size, char *old_tablespace);
+static void transfer_single_new_db(FileNameMap *maps, int size, char *old_tablespace, char *new_tablespace);
static void transfer_relfile(FileNameMap *map, const char *type_suffix, bool vm_must_add_frozenbit);
/*
@@ -136,21 +136,22 @@ transfer_all_new_tablespaces(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
*/
if (user_opts.jobs <= 1)
parallel_transfer_all_new_dbs(old_db_arr, new_db_arr, old_pgdata,
- new_pgdata, NULL);
+ new_pgdata, NULL, NULL);
else
{
int tblnum;
/* transfer default tablespace */
parallel_transfer_all_new_dbs(old_db_arr, new_db_arr, old_pgdata,
- new_pgdata, old_pgdata);
+ new_pgdata, old_pgdata, new_pgdata);
- for (tblnum = 0; tblnum < os_info.num_old_tablespaces; tblnum++)
+ for (tblnum = 0; tblnum < old_cluster.num_tablespaces; tblnum++)
parallel_transfer_all_new_dbs(old_db_arr,
new_db_arr,
old_pgdata,
new_pgdata,
- os_info.old_tablespaces[tblnum]);
+ old_cluster.tablespaces[tblnum],
+ new_cluster.tablespaces[tblnum]);
/* reap all children */
while (reap_child(true) == true)
;
@@ -169,7 +170,8 @@ transfer_all_new_tablespaces(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
*/
void
transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
- char *old_pgdata, char *new_pgdata, char *old_tablespace)
+ char *old_pgdata, char *new_pgdata,
+ char *old_tablespace, char *new_tablespace)
{
int old_dbnum,
new_dbnum;
@@ -204,7 +206,7 @@ transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
new_pgdata);
if (n_maps)
{
- transfer_single_new_db(mappings, n_maps, old_tablespace);
+ transfer_single_new_db(mappings, n_maps, old_tablespace, new_tablespace);
}
/* We allocate something even for n_maps == 0 */
pg_free(mappings);
@@ -234,10 +236,10 @@ transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
* moved_db_dir: Destination for the pg_restore-generated database directory.
*/
static bool
-prepare_for_swap(const char *old_tablespace, Oid db_oid,
- char *old_catalog_dir, char *new_db_dir, char *moved_db_dir)
+prepare_for_swap(const char *old_tablespace, const char *new_tablespace,
+ Oid db_oid, char *old_catalog_dir, char *new_db_dir,
+ char *moved_db_dir)
{
- const char *new_tablespace;
const char *old_tblspc_suffix;
const char *new_tblspc_suffix;
char old_tblspc[MAXPGPATH];
@@ -247,24 +249,14 @@ prepare_for_swap(const char *old_tablespace, Oid db_oid,
struct stat st;
if (strcmp(old_tablespace, old_cluster.pgdata) == 0)
- {
- new_tablespace = new_cluster.pgdata;
- new_tblspc_suffix = "/base";
old_tblspc_suffix = "/base";
- }
else
- {
- /*
- * XXX: The below line is a hack to deal with the fact that we
- * presently don't have an easy way to find the corresponding new
- * tablespace's path. This will need to be fixed if/when we add
- * pg_upgrade support for in-place tablespaces.
- */
- new_tablespace = old_tablespace;
+ old_tblspc_suffix = old_cluster.tablespace_suffix;
+ if (strcmp(new_tablespace, new_cluster.pgdata) == 0)
+ new_tblspc_suffix = "/base";
+ else
new_tblspc_suffix = new_cluster.tablespace_suffix;
- old_tblspc_suffix = old_cluster.tablespace_suffix;
- }
/* Old and new cluster paths. */
snprintf(old_tblspc, sizeof(old_tblspc), "%s%s", old_tablespace, old_tblspc_suffix);
@@ -450,7 +442,7 @@ swap_catalog_files(FileNameMap *maps, int size, const char *old_catalog_dir,
* during pg_restore.
*/
static void
-do_swap(FileNameMap *maps, int size, char *old_tablespace)
+do_swap(FileNameMap *maps, int size, char *old_tablespace, char *new_tablespace)
{
char old_catalog_dir[MAXPGPATH];
char new_db_dir[MAXPGPATH];
@@ -470,21 +462,23 @@ do_swap(FileNameMap *maps, int size, char *old_tablespace)
*/
if (old_tablespace)
{
- if (prepare_for_swap(old_tablespace, maps[0].db_oid,
+ if (prepare_for_swap(old_tablespace, new_tablespace, maps[0].db_oid,
old_catalog_dir, new_db_dir, moved_db_dir))
swap_catalog_files(maps, size,
old_catalog_dir, new_db_dir, moved_db_dir);
}
else
{
- if (prepare_for_swap(old_cluster.pgdata, maps[0].db_oid,
+ if (prepare_for_swap(old_cluster.pgdata, new_cluster.pgdata, maps[0].db_oid,
old_catalog_dir, new_db_dir, moved_db_dir))
swap_catalog_files(maps, size,
old_catalog_dir, new_db_dir, moved_db_dir);
- for (int tblnum = 0; tblnum < os_info.num_old_tablespaces; tblnum++)
+ for (int tblnum = 0; tblnum < old_cluster.num_tablespaces; tblnum++)
{
- if (prepare_for_swap(os_info.old_tablespaces[tblnum], maps[0].db_oid,
+ if (prepare_for_swap(old_cluster.tablespaces[tblnum],
+ new_cluster.tablespaces[tblnum],
+ maps[0].db_oid,
old_catalog_dir, new_db_dir, moved_db_dir))
swap_catalog_files(maps, size,
old_catalog_dir, new_db_dir, moved_db_dir);
@@ -498,7 +492,8 @@ do_swap(FileNameMap *maps, int size, char *old_tablespace)
* create links for mappings stored in "maps" array.
*/
static void
-transfer_single_new_db(FileNameMap *maps, int size, char *old_tablespace)
+transfer_single_new_db(FileNameMap *maps, int size,
+ char *old_tablespace, char *new_tablespace)
{
int mapnum;
bool vm_must_add_frozenbit = false;
@@ -520,7 +515,7 @@ transfer_single_new_db(FileNameMap *maps, int size, char *old_tablespace)
*/
Assert(!vm_must_add_frozenbit);
- do_swap(maps, size, old_tablespace);
+ do_swap(maps, size, old_tablespace, new_tablespace);
return;
}
diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl
index 550a63fdf7d..7302c438b3d 100644
--- a/src/bin/pg_upgrade/t/006_transfer_modes.pl
+++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl
@@ -37,6 +37,12 @@ sub test_mode
}
$new->init();
+ if (!defined($ENV{oldinstall}))
+ {
+ $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true");
+ $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true");
+ }
+
# Create a small variety of simple test objects on the old cluster. We'll
# check that these reach the new version after upgrading.
$old->start;
@@ -46,16 +52,15 @@ sub test_mode
$old->safe_psql('testdb1', "VACUUM FULL test2");
$old->safe_psql('testdb1', "CREATE SEQUENCE testseq START 5432");
- # For cross-version tests, we can also check that pg_upgrade handles
- # tablespaces.
+ my $tblspc = '';
if (defined($ENV{oldinstall}))
{
- my $tblspc = PostgreSQL::Test::Utils::tempdir_short();
- $old->safe_psql('postgres', "CREATE TABLESPACE test_tblspc LOCATION '$tblspc'");
- $old->safe_psql('postgres', "CREATE DATABASE testdb2 TABLESPACE test_tblspc");
- $old->safe_psql('postgres', "CREATE TABLE test3 TABLESPACE test_tblspc AS SELECT generate_series(300, 401)");
- $old->safe_psql('testdb2', "CREATE TABLE test4 AS SELECT generate_series(400, 502)");
+ $tblspc = PostgreSQL::Test::Utils::tempdir_short();
}
+ $old->safe_psql('postgres', "CREATE TABLESPACE test_tblspc LOCATION '$tblspc'");
+ $old->safe_psql('postgres', "CREATE DATABASE testdb2 TABLESPACE test_tblspc");
+ $old->safe_psql('postgres', "CREATE TABLE test3 TABLESPACE test_tblspc AS SELECT generate_series(300, 401)");
+ $old->safe_psql('testdb2', "CREATE TABLE test4 AS SELECT generate_series(400, 502)");
$old->stop;
my $result = command_ok_or_fails_like(
@@ -85,16 +90,10 @@ sub test_mode
is($result, '101', "test2 data after pg_upgrade $mode");
$result = $new->safe_psql('testdb1', "SELECT nextval('testseq')");
is($result, '5432', "sequence data after pg_upgrade $mode");
-
- # For cross-version tests, we should have some objects in a non-default
- # tablespace.
- if (defined($ENV{oldinstall}))
- {
- $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test3");
- is($result, '102', "test3 data after pg_upgrade $mode");
- $result = $new->safe_psql('testdb2', "SELECT COUNT(*) FROM test4");
- is($result, '103', "test4 data after pg_upgrade $mode");
- }
+ $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test3");
+ is($result, '102', "test3 data after pg_upgrade $mode");
+ $result = $new->safe_psql('testdb2', "SELECT COUNT(*) FROM test4");
+ is($result, '103', "test4 data after pg_upgrade $mode");
$new->stop;
}
diff --git a/src/bin/pg_upgrade/tablespace.c b/src/bin/pg_upgrade/tablespace.c
index 3520a75ba31..178fce9fe34 100644
--- a/src/bin/pg_upgrade/tablespace.c
+++ b/src/bin/pg_upgrade/tablespace.c
@@ -23,10 +23,20 @@ init_tablespaces(void)
set_tablespace_directory_suffix(&old_cluster);
set_tablespace_directory_suffix(&new_cluster);
- if (os_info.num_old_tablespaces > 0 &&
+ if (old_cluster.num_tablespaces > 0 &&
strcmp(old_cluster.tablespace_suffix, new_cluster.tablespace_suffix) == 0)
- pg_fatal("Cannot upgrade to/from the same system catalog version when\n"
- "using tablespaces.");
+ {
+ for (int i = 0; i < old_cluster.num_tablespaces; i++)
+ {
+ /*
+ * In-place tablespaces are okay for same-version upgrades because
+ * their paths will differ between clusters.
+ */
+ if (strcmp(old_cluster.tablespaces[i], new_cluster.tablespaces[i]) == 0)
+ pg_fatal("Cannot upgrade to/from the same system catalog version when\n"
+ "using tablespaces.");
+ }
+ }
}
@@ -53,19 +63,44 @@ get_tablespace_paths(void)
res = executeQueryOrDie(conn, "%s", query);
- if ((os_info.num_old_tablespaces = PQntuples(res)) != 0)
- os_info.old_tablespaces =
- (char **) pg_malloc(os_info.num_old_tablespaces * sizeof(char *));
+ old_cluster.num_tablespaces = PQntuples(res);
+ new_cluster.num_tablespaces = PQntuples(res);
+
+ if (PQntuples(res) != 0)
+ {
+ old_cluster.tablespaces =
+ (char **) pg_malloc(old_cluster.num_tablespaces * sizeof(char *));
+ new_cluster.tablespaces =
+ (char **) pg_malloc(new_cluster.num_tablespaces * sizeof(char *));
+ }
else
- os_info.old_tablespaces = NULL;
+ {
+ old_cluster.tablespaces = NULL;
+ new_cluster.tablespaces = NULL;
+ }
i_spclocation = PQfnumber(res, "spclocation");
- for (tblnum = 0; tblnum < os_info.num_old_tablespaces; tblnum++)
+ for (tblnum = 0; tblnum < old_cluster.num_tablespaces; tblnum++)
{
struct stat statBuf;
+ char *spcloc = PQgetvalue(res, tblnum, i_spclocation);
- os_info.old_tablespaces[tblnum] = pg_strdup(PQgetvalue(res, tblnum, i_spclocation));
+ /*
+ * For now, we do not expect non-in-place tablespaces to move during
+ * upgrade. If that changes, it will likely become necessary to run
+ * the above query on the new cluster, too.
+ */
+ if (is_absolute_path(PQgetvalue(res, tblnum, i_spclocation)))
+ {
+ old_cluster.tablespaces[tblnum] = pg_strdup(spcloc);
+ new_cluster.tablespaces[tblnum] = old_cluster.tablespaces[tblnum];
+ }
+ else
+ {
+ old_cluster.tablespaces[tblnum] = psprintf("%s/%s", old_cluster.pgdata, spcloc);
+ new_cluster.tablespaces[tblnum] = psprintf("%s/%s", new_cluster.pgdata, spcloc);
+ }
/*
* Check that the tablespace path exists and is a directory.
@@ -76,21 +111,21 @@ get_tablespace_paths(void)
* that contains user tablespaces is moved as part of pg_upgrade
* preparation and the symbolic links are not updated.
*/
- if (stat(os_info.old_tablespaces[tblnum], &statBuf) != 0)
+ if (stat(old_cluster.tablespaces[tblnum], &statBuf) != 0)
{
if (errno == ENOENT)
report_status(PG_FATAL,
"tablespace directory \"%s\" does not exist",
- os_info.old_tablespaces[tblnum]);
+ old_cluster.tablespaces[tblnum]);
else
report_status(PG_FATAL,
"could not stat tablespace directory \"%s\": %m",
- os_info.old_tablespaces[tblnum]);
+ old_cluster.tablespaces[tblnum]);
}
if (!S_ISDIR(statBuf.st_mode))
report_status(PG_FATAL,
"tablespace path \"%s\" is not a directory",
- os_info.old_tablespaces[tblnum]);
+ old_cluster.tablespaces[tblnum]);
}
PQclear(res);
--
2.39.5 (Apple Git-154)
^ permalink raw reply [nested|flat] 4308+ messages in thread
* Re: teach pg_upgrade to handle in-place tablespaces
2025-04-28 21:07 teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
2025-04-28 22:01 ` Re: teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
@ 2025-07-01 20:06 ` Nathan Bossart <[email protected]>
2025-07-22 00:16 ` Re: teach pg_upgrade to handle in-place tablespaces Corey Huinker <[email protected]>
0 siblings, 1 reply; 4308+ messages in thread
From: Nathan Bossart @ 2025-07-01 20:06 UTC (permalink / raw)
To: pgsql-hackers
rebased
--
nathan
^ permalink raw reply [nested|flat] 4308+ messages in thread
* Re: teach pg_upgrade to handle in-place tablespaces
2025-04-28 21:07 teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
2025-04-28 22:01 ` Re: teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
2025-07-01 20:06 ` Re: teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
@ 2025-07-22 00:16 ` Corey Huinker <[email protected]>
2025-07-22 00:57 ` Re: teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
0 siblings, 1 reply; 4308+ messages in thread
From: Corey Huinker @ 2025-07-22 00:16 UTC (permalink / raw)
To: Nathan Bossart <[email protected]>; +Cc: pgsql-hackers
On Tue, Jul 1, 2025 at 4:06 PM Nathan Bossart <[email protected]>
wrote:
> rebased
>
> --
> nathan
Everything here makes sense to me, but I do have one question:
In src/bin/pg_upgrade/info.c
@@ -616,11 +630,21 @@ process_rel_infos(DbInfo *dbinfo, PGresult *res, void
*arg)
+ if (inplace)
+ tablespace = psprintf("%s/%s",
+ os_info.running_cluster->pgdata,
+ PQgetvalue(res, relnum, i_spclocation));
+ else
+ tablespace = PQgetvalue(res, relnum, i_spclocation);
I'm sure it's no big deal, but we've already PQgetvalue() fetched that once
for spcloc, and we're going to fetch it again no matter what the value of
inplace is. Is there a reason to not reuse spcloc?
^ permalink raw reply [nested|flat] 4308+ messages in thread
* Re: teach pg_upgrade to handle in-place tablespaces
2025-04-28 21:07 teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
2025-04-28 22:01 ` Re: teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
2025-07-01 20:06 ` Re: teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
2025-07-22 00:16 ` Re: teach pg_upgrade to handle in-place tablespaces Corey Huinker <[email protected]>
@ 2025-07-22 00:57 ` Nathan Bossart <[email protected]>
2025-07-22 01:37 ` Re: teach pg_upgrade to handle in-place tablespaces Michael Paquier <[email protected]>
0 siblings, 1 reply; 4308+ messages in thread
From: Nathan Bossart @ 2025-07-22 00:57 UTC (permalink / raw)
To: Corey Huinker <[email protected]>; +Cc: pgsql-hackers
On Mon, Jul 21, 2025 at 08:16:12PM -0400, Corey Huinker wrote:
> Everything here makes sense to me, but I do have one question:
Thanks for reviewing.
> In src/bin/pg_upgrade/info.c
> @@ -616,11 +630,21 @@ process_rel_infos(DbInfo *dbinfo, PGresult *res, void
> *arg)
> + if (inplace)
> + tablespace = psprintf("%s/%s",
> + os_info.running_cluster->pgdata,
> + PQgetvalue(res, relnum, i_spclocation));
> + else
> + tablespace = PQgetvalue(res, relnum, i_spclocation);
>
> I'm sure it's no big deal, but we've already PQgetvalue() fetched that once
> for spcloc, and we're going to fetch it again no matter what the value of
> inplace is. Is there a reason to not reuse spcloc?
I can't think of any reason. Fixed in v4.
--
nathan
^ permalink raw reply [nested|flat] 4308+ messages in thread
* Re: teach pg_upgrade to handle in-place tablespaces
2025-04-28 21:07 teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
2025-04-28 22:01 ` Re: teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
2025-07-01 20:06 ` Re: teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
2025-07-22 00:16 ` Re: teach pg_upgrade to handle in-place tablespaces Corey Huinker <[email protected]>
2025-07-22 00:57 ` Re: teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
@ 2025-07-22 01:37 ` Michael Paquier <[email protected]>
2025-07-22 02:06 ` Re: teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
0 siblings, 1 reply; 4308+ messages in thread
From: Michael Paquier @ 2025-07-22 01:37 UTC (permalink / raw)
To: Nathan Bossart <[email protected]>; +Cc: Corey Huinker <[email protected]>; pgsql-hackers
On Mon, Jul 21, 2025 at 07:57:32PM -0500, Nathan Bossart wrote:
+ if (!defined($ENV{oldinstall}))
+ {
+ $new->append_conf('postgresql.conf',
+ "allow_in_place_tablespaces = true");
+ $old->append_conf('postgresql.conf',
+ "allow_in_place_tablespaces = true");
+ }
This would not choke as long as the old cluster is at least at v10,
but well why not.
- # For cross-version tests, we can also check that pg_upgrade handles
- # tablespaces.
+ my $tblspc = '';
if (defined($ENV{oldinstall}))
{
- my $tblspc = PostgreSQL::Test::Utils::tempdir_short();
- $old->safe_psql('postgres',
- "CREATE TABLESPACE test_tblspc LOCATION '$tblspc'");
- $old->safe_psql('postgres',
- "CREATE DATABASE testdb2 TABLESPACE test_tblspc");
- $old->safe_psql('postgres',
- "CREATE TABLE test3 TABLESPACE test_tblspc AS SELECT generate_series(300, 401)"
- );
- $old->safe_psql('testdb2',
- "CREATE TABLE test4 AS SELECT generate_series(400, 502)");
+ $tblspc = PostgreSQL::Test::Utils::tempdir_short();
}
+ $old->safe_psql('postgres',
+ "CREATE TABLESPACE test_tblspc LOCATION '$tblspc'");
+ $old->safe_psql('postgres',
+ "CREATE DATABASE testdb2 TABLESPACE test_tblspc");
+ $old->safe_psql('postgres',
+ "CREATE TABLE test3 TABLESPACE test_tblspc AS SELECT generate_series(300, 401)"
+ );
+ $old->safe_psql('testdb2',
+ "CREATE TABLE test4 AS SELECT generate_series(400, 502)");
$old->stop;
I would vote for having a total of two tablespaces when we can do so
safely: one non-inplace and one inplace, strengthening the
cross-checks for the prefixes assigned in the new paths when doing a
swap of the tablespace paths, even when an old installation is tested.
+ /*
+ * For now, we do not expect non-in-place tablespaces to move during
+ * upgrade. If that changes, it will likely become necessary to run
+ * the above query on the new cluster, too.
+ */
Curiosity matter: has this ever been discussed? Spoiler: I don't
recall so and why it would ever matter as tbspace OIDs should be fixed
across upgrades these days (right?).
@@ -53,19 +63,44 @@ get_tablespace_paths(void)
[...]
+ if (is_absolute_path(PQgetvalue(res, tblnum, i_spclocation)))
+ {
This use of is_absolute_path() should document that it is for in-place
tablespaces?
+ if (strcmp(new_tablespace, new_cluster.pgdata) == 0)
+ new_tblspc_suffix = "/base";
This knowledge is encapsulated in GetDatabasePath() currently. Not
new, just saying that it could be nice to reduce the footprint of this
knowledge in pg_upgrade. Perhaps not something to worry about here,
though.
--
Michael
Attachments:
[application/pgp-signature] signature.asc (833B, ../../[email protected]/2-signature.asc)
download
^ permalink raw reply [nested|flat] 4308+ messages in thread
* Re: teach pg_upgrade to handle in-place tablespaces
2025-04-28 21:07 teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
2025-04-28 22:01 ` Re: teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
2025-07-01 20:06 ` Re: teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
2025-07-22 00:16 ` Re: teach pg_upgrade to handle in-place tablespaces Corey Huinker <[email protected]>
2025-07-22 00:57 ` Re: teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
2025-07-22 01:37 ` Re: teach pg_upgrade to handle in-place tablespaces Michael Paquier <[email protected]>
@ 2025-07-22 02:06 ` Nathan Bossart <[email protected]>
2025-07-22 02:17 ` Re: teach pg_upgrade to handle in-place tablespaces Michael Paquier <[email protected]>
0 siblings, 1 reply; 4308+ messages in thread
From: Nathan Bossart @ 2025-07-22 02:06 UTC (permalink / raw)
To: Michael Paquier <[email protected]>; +Cc: Corey Huinker <[email protected]>; pgsql-hackers
On Tue, Jul 22, 2025 at 10:37:05AM +0900, Michael Paquier wrote:
> On Mon, Jul 21, 2025 at 07:57:32PM -0500, Nathan Bossart wrote:
> + if (!defined($ENV{oldinstall}))
> + {
> + $new->append_conf('postgresql.conf',
> + "allow_in_place_tablespaces = true");
> + $old->append_conf('postgresql.conf',
> + "allow_in_place_tablespaces = true");
> + }
>
> This would not choke as long as the old cluster is at least at v10,
> but well why not.
I'm not sure what you mean. allow_in_place_tablespaces was added in v15,
right?
> I would vote for having a total of two tablespaces when we can do so
> safely: one non-inplace and one inplace, strengthening the
> cross-checks for the prefixes assigned in the new paths when doing a
> swap of the tablespace paths, even when an old installation is tested.
Seems reasonable, will add this.
> + /*
> + * For now, we do not expect non-in-place tablespaces to move during
> + * upgrade. If that changes, it will likely become necessary to run
> + * the above query on the new cluster, too.
> + */
>
> Curiosity matter: has this ever been discussed? Spoiler: I don't
> recall so and why it would ever matter as tbspace OIDs should be fixed
> across upgrades these days (right?).
I'm not aware of any such discussion. I know there was a time before
version-specific tablespace subdirectories were a thing, but that is long
gone. And yeah, we've preserved tablespace OIDs since v15.
> + if (is_absolute_path(PQgetvalue(res, tblnum, i_spclocation)))
> + {
>
> This use of is_absolute_path() should document that it is for in-place
> tablespaces?
Yes.
> + if (strcmp(new_tablespace, new_cluster.pgdata) == 0)
> + new_tblspc_suffix = "/base";
>
> This knowledge is encapsulated in GetDatabasePath() currently. Not
> new, just saying that it could be nice to reduce the footprint of this
> knowledge in pg_upgrade. Perhaps not something to worry about here,
> though.
I'll take a look and see what I can do.
--
nathan
^ permalink raw reply [nested|flat] 4308+ messages in thread
* Re: teach pg_upgrade to handle in-place tablespaces
2025-04-28 21:07 teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
2025-04-28 22:01 ` Re: teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
2025-07-01 20:06 ` Re: teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
2025-07-22 00:16 ` Re: teach pg_upgrade to handle in-place tablespaces Corey Huinker <[email protected]>
2025-07-22 00:57 ` Re: teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
2025-07-22 01:37 ` Re: teach pg_upgrade to handle in-place tablespaces Michael Paquier <[email protected]>
2025-07-22 02:06 ` Re: teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
@ 2025-07-22 02:17 ` Michael Paquier <[email protected]>
2025-07-24 18:44 ` Re: teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
0 siblings, 1 reply; 4308+ messages in thread
From: Michael Paquier @ 2025-07-22 02:17 UTC (permalink / raw)
To: Nathan Bossart <[email protected]>; +Cc: Corey Huinker <[email protected]>; pgsql-hackers
On Mon, Jul 21, 2025 at 09:06:59PM -0500, Nathan Bossart wrote:
> On Tue, Jul 22, 2025 at 10:37:05AM +0900, Michael Paquier wrote:
>> This would not choke as long as the old cluster is at least at v10,
>> but well why not.
>
> I'm not sure what you mean. allow_in_place_tablespaces was added in v15,
> right?
Yes initially, not so these days. Here are the backpatches across
v10~14:
<16e7a8fd8e97> 2022-07-27 [Alvaro Herrera] Allow "in place" tablespaces.
<961cab0a5a90> 2022-07-27 [Alvaro Herrera] Allow "in place" tablespaces.
<7bdbbb87340f> 2022-07-27 [Alvaro Herrera] Allow "in place" tablespaces.
<258c896418bf> 2022-07-27 [Alvaro Herrera] Allow "in place" tablespaces.
<ca347f5433ed> 2022-07-27 [Alvaro Herrera] Allow "in place" tablespaces.
--
Michael
Attachments:
[application/pgp-signature] signature.asc (833B, ../../[email protected]/2-signature.asc)
download
^ permalink raw reply [nested|flat] 4308+ messages in thread
* Re: teach pg_upgrade to handle in-place tablespaces
2025-04-28 21:07 teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
2025-04-28 22:01 ` Re: teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
2025-07-01 20:06 ` Re: teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
2025-07-22 00:16 ` Re: teach pg_upgrade to handle in-place tablespaces Corey Huinker <[email protected]>
2025-07-22 00:57 ` Re: teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
2025-07-22 01:37 ` Re: teach pg_upgrade to handle in-place tablespaces Michael Paquier <[email protected]>
2025-07-22 02:06 ` Re: teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
2025-07-22 02:17 ` Re: teach pg_upgrade to handle in-place tablespaces Michael Paquier <[email protected]>
@ 2025-07-24 18:44 ` Nathan Bossart <[email protected]>
2025-07-30 15:52 ` Re: teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
0 siblings, 1 reply; 4308+ messages in thread
From: Nathan Bossart @ 2025-07-24 18:44 UTC (permalink / raw)
To: Michael Paquier <[email protected]>; +Cc: Corey Huinker <[email protected]>; pgsql-hackers
On Tue, Jul 22, 2025 at 11:17:42AM +0900, Michael Paquier wrote:
> On Mon, Jul 21, 2025 at 09:06:59PM -0500, Nathan Bossart wrote:
>> On Tue, Jul 22, 2025 at 10:37:05AM +0900, Michael Paquier wrote:
>>> This would not choke as long as the old cluster is at least at v10,
>>> but well why not.
>>
>> I'm not sure what you mean. allow_in_place_tablespaces was added in v15,
>> right?
>
> Yes initially, not so these days. Here are the backpatches across
> v10~14:
Ah, I see. Here's a new patch that should address all your feedback except
for the part about "/base". I figure we can leave that for another patch.
--
nathan
^ permalink raw reply [nested|flat] 4308+ messages in thread
* Re: teach pg_upgrade to handle in-place tablespaces
2025-04-28 21:07 teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
2025-04-28 22:01 ` Re: teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
2025-07-01 20:06 ` Re: teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
2025-07-22 00:16 ` Re: teach pg_upgrade to handle in-place tablespaces Corey Huinker <[email protected]>
2025-07-22 00:57 ` Re: teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
2025-07-22 01:37 ` Re: teach pg_upgrade to handle in-place tablespaces Michael Paquier <[email protected]>
2025-07-22 02:06 ` Re: teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
2025-07-22 02:17 ` Re: teach pg_upgrade to handle in-place tablespaces Michael Paquier <[email protected]>
2025-07-24 18:44 ` Re: teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
@ 2025-07-30 15:52 ` Nathan Bossart <[email protected]>
0 siblings, 0 replies; 4308+ messages in thread
From: Nathan Bossart @ 2025-07-30 15:52 UTC (permalink / raw)
To: Michael Paquier <[email protected]>; +Cc: Corey Huinker <[email protected]>; pgsql-hackers
Committed.
--
nathan
^ permalink raw reply [nested|flat] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID 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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 13 +++------
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use CREATE OR REPLACE FUNCTION to handle the
optional pretty argument for both versions that use OID or view name.
---
src/backend/catalog/system_functions.sql | 14 ++++++++
src/backend/utils/adt/ruleutils.c | 44 ------------------------
src/include/catalog/pg_proc.dat | 11 ++----
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] 4308+ 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; 4308+ messages in thread
From: Mark Wong @ 2025-12-09 17:33 UTC (permalink / raw)
Modernize pg_get_viewdef to use proargdefaults to handle the optional
pretty argument for both versions that use OID or view name.
---
src/backend/utils/adt/ruleutils.c | 44 -------------------------------
src/include/catalog/pg_proc.dat | 17 +++++-------
2 files changed, 6 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 76705db3dac..fd00d6c3515 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -669,25 +669,6 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags)
*/
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
-{
- /* By OID */
- Oid viewoid = PG_GETARG_OID(0);
- int prettyFlags;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_ext(PG_FUNCTION_ARGS)
{
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
@@ -727,31 +708,6 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef_name(PG_FUNCTION_ARGS)
-{
- /* By qualified name */
- text *viewname = PG_GETARG_TEXT_PP(0);
- int prettyFlags;
- RangeVar *viewrel;
- Oid viewoid;
- char *res;
-
- prettyFlags = PRETTYFLAG_INDENT;
-
- /* Look up view name. Can't lock it - we might not have privileges. */
- viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname));
- viewoid = RangeVarGetRelid(viewrel, NoLock, false);
-
- res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
-
- if (res == NULL)
- PG_RETURN_NULL();
-
- PG_RETURN_TEXT_P(string_to_text(res));
-}
-
-
-Datum
-pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
{
/* By qualified name */
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] 4308+ messages in thread
end of thread, other threads:[~2025-12-09 17:33 UTC | newest]
Thread overview: 4308+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-03-07 17:22 [PATCH 1/3] Add operator <->(box, point) Nikita Glukhov <[email protected]>
2019-03-07 17:22 [PATCH 1/3] Add operator <->(box, point) Nikita Glukhov <[email protected]>
2023-06-25 11:48 [PATCH v1 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-06-25 11:48 [PATCH v1 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-06-25 11:48 [PATCH v1 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-06-25 11:48 [PATCH v1 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-06-25 11:48 [PATCH v1 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-06-26 08:05 [PATCH v2 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-06-26 08:05 [PATCH v2 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-06-26 08:05 [PATCH v2 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-06-26 08:05 [PATCH v2 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-06-26 08:05 [PATCH v2 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-07-26 10:49 [PATCH v3 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-07-26 10:49 [PATCH v3 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-07-26 10:49 [PATCH v3 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-07-26 10:49 [PATCH v3 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-07-26 10:49 [PATCH v3 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-08-09 07:56 [PATCH v4 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-08-09 07:56 [PATCH v4 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-08-09 07:56 [PATCH v4 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-08-09 07:56 [PATCH v4 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-08-09 07:56 [PATCH v4 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-08-09 07:56 [PATCH v4 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-09-02 06:32 [PATCH v5 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-09-02 06:32 [PATCH v5 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-09-02 06:32 [PATCH v5 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-09-02 06:32 [PATCH v5 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-09-02 06:32 [PATCH v5 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-09-02 06:32 [PATCH v5 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-09-12 05:22 [PATCH v6 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-09-12 05:22 [PATCH v6 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-09-12 05:22 [PATCH v6 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-09-12 05:22 [PATCH v6 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-09-12 05:22 [PATCH v6 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-09-12 05:22 [PATCH v6 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-09-12 05:22 [PATCH v6 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-09-22 04:53 [PATCH v7 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-09-22 04:53 [PATCH v7 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-09-22 04:53 [PATCH v7 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-09-22 04:53 [PATCH v7 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-09-22 04:53 [PATCH v7 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-09-25 05:01 [PATCH v8 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-09-25 05:01 [PATCH v8 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-09-25 05:01 [PATCH v8 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-09-25 05:01 [PATCH v8 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-10-04 05:51 [PATCH v9 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-10-04 05:51 [PATCH v9 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-10-04 05:51 [PATCH v9 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-10-04 05:51 [PATCH v9 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-10-22 02:22 [PATCH v10 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-10-22 02:22 [PATCH v10 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-10-22 02:22 [PATCH v10 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-10-22 02:22 [PATCH v10 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-11-08 06:57 [PATCH v11 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-11-08 06:57 [PATCH v11 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-11-08 06:57 [PATCH v11 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-12-04 11:23 [PATCH v12 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-12-04 11:23 [PATCH v12 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2023-12-04 11:23 [PATCH v12 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-01-22 09:45 [PATCH v13 4/8] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-01-22 09:45 [PATCH v13 4/8] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-01-22 09:45 [PATCH v13 4/8] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-02-28 13:59 [PATCH v14 4/8] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-02-28 13:59 [PATCH v14 4/8] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-02-28 13:59 [PATCH v14 4/8] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-03-28 10:30 [PATCH v15 4/8] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-03-28 10:30 [PATCH v15 4/8] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-03-28 10:30 [PATCH v15 4/8] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-03-28 10:30 [PATCH v15 4/8] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-03-28 10:30 [PATCH v15 4/8] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-04-12 06:49 [PATCH v16 4/8] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-04-12 06:49 [PATCH v16 4/8] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-04-12 06:49 [PATCH v16 4/8] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-04-28 11:00 [PATCH v17 4/8] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-04-28 11:00 [PATCH v17 4/8] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-04-28 11:00 [PATCH v17 4/8] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-05-11 07:11 [PATCH v18 4/8] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-05-11 07:11 [PATCH v18 4/8] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-05-11 07:11 [PATCH v18 4/8] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-05-14 23:26 [PATCH v19 4/8] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-05-14 23:26 [PATCH v19 4/8] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-05-14 23:26 [PATCH v19 4/8] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-05-24 02:26 [PATCH v20 4/8] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-05-24 02:26 [PATCH v20 4/8] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-05-24 02:26 [PATCH v20 4/8] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-08-26 04:32 [PATCH v21 4/8] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-08-26 04:32 [PATCH v21 4/8] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-08-26 04:32 [PATCH v21 4/8] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-09-19 04:48 [PATCH v22 4/8] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-09-19 04:48 [PATCH v22 4/8] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-09-19 04:48 [PATCH v22 4/8] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-10-25 03:56 [PATCH v23 4/8] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-10-25 03:56 [PATCH v23 4/8] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-10-25 03:56 [PATCH v23 4/8] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-12-19 06:06 [PATCH v24 4/8] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-12-19 06:06 [PATCH v24 4/8] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-12-19 06:06 [PATCH v24 4/8] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-12-21 06:19 [PATCH v25 4/9] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-12-21 06:19 [PATCH v25 4/9] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-12-21 06:19 [PATCH v25 4/9] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-12-30 12:44 [PATCH v26 4/9] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-12-30 12:44 [PATCH v26 4/9] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-12-30 12:44 [PATCH v26 4/9] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-12-30 23:53 [PATCH v27 4/9] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-12-30 23:53 [PATCH v27 4/9] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2024-12-30 23:53 [PATCH v27 4/9] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
2025-04-28 21:07 teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
2025-04-28 22:01 ` Re: teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
2025-07-01 20:06 ` Re: teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
2025-07-22 00:16 ` Re: teach pg_upgrade to handle in-place tablespaces Corey Huinker <[email protected]>
2025-07-22 00:57 ` Re: teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
2025-07-22 01:37 ` Re: teach pg_upgrade to handle in-place tablespaces Michael Paquier <[email protected]>
2025-07-22 02:06 ` Re: teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
2025-07-22 02:17 ` Re: teach pg_upgrade to handle in-place tablespaces Michael Paquier <[email protected]>
2025-07-24 18:44 ` Re: teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[email protected]>
2025-07-30 15:52 ` Re: teach pg_upgrade to handle in-place tablespaces Nathan Bossart <[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 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 v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 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 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 v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 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.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 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 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 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 v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 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 v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 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 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 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 v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 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 v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 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 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 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 v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 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 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 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 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 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 v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 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 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 v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 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 v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 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 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 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 v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 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 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 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 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 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 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 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 v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 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 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 v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 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 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 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 v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 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 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 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 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 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 v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 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 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 v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 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 v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 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 v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 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 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 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 v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 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 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 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 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 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 v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 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 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 v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 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 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 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 v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 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 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 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 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 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 v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 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 v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 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 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 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 v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 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.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 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 v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 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 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 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 v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 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 v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 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 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 v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 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 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 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 v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 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 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 v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 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 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 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 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 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 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 v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 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 v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 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 v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 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 v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v3 3/7] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8.1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v4 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v7 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v8 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 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 v2 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v1 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH v5 2/6] Handle pg_get_viewdef default args in system_functions.sql Mark Wong <[email protected]>
2025-12-09 17:33 [PATCH 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 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]>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox