diff options
| author | Tom Lane | 2017-07-24 19:16:31 +0000 |
|---|---|---|
| committer | Tom Lane | 2017-07-24 19:16:31 +0000 |
| commit | b4af9e3f378ef56fa48b98a0bfb641900b0280dc (patch) | |
| tree | dfa7ea96453a9f43bdd04e957acd901e527fc185 /src/test | |
| parent | 278cb4341103e967189997985b09981a73e23a34 (diff) | |
Ensure that pg_get_ruledef()'s output matches pg_get_viewdef()'s.
Various cases involving renaming of view columns are handled by having
make_viewdef pass down the view's current relation tupledesc to
get_query_def, which then takes care to use the column names from the
tupledesc for the output column names of the SELECT. For some reason
though, we'd missed teaching make_ruledef to do similarly when it is
printing an ON SELECT rule, even though this is exactly the same case.
The results from pg_get_ruledef would then be different and arguably wrong.
In particular, this breaks pre-v10 versions of pg_dump, which in some
situations would define views by means of emitting a CREATE RULE ... ON
SELECT command. Third-party tools might not be happy either.
In passing, clean up some crufty code in make_viewdef; we'd apparently
modernized the equivalent code in make_ruledef somewhere along the way,
and missed this copy.
Per report from Gilles Darold. Back-patch to all supported versions.
Discussion: https://postgr.es/m/ec05659a-40ff-4510-fc45-ca9d965d0838@dalibo.com
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/regress/expected/create_view.out | 29 | ||||
| -rw-r--r-- | src/test/regress/sql/create_view.sql | 11 |
2 files changed, 40 insertions, 0 deletions
diff --git a/src/test/regress/expected/create_view.out b/src/test/regress/expected/create_view.out index c2da9add97e..34f0b7641d4 100644 --- a/src/test/regress/expected/create_view.out +++ b/src/test/regress/expected/create_view.out @@ -1677,6 +1677,35 @@ select pg_get_viewdef('tt22v', true); LEFT JOIN tt6 ON TRUE; (1 row) +-- check handling of views with immediately-renamed columns +create view tt23v (col_a, col_b) as +select q1 as other_name1, q2 as other_name2 from int8_tbl +union +select 42, 43; +select pg_get_viewdef('tt23v', true); + pg_get_viewdef +------------------------------- + SELECT int8_tbl.q1 AS col_a,+ + int8_tbl.q2 AS col_b + + FROM int8_tbl + + UNION + + SELECT 42 AS col_a, + + 43 AS col_b; +(1 row) + +select pg_get_ruledef(oid, true) from pg_rewrite + where ev_class = 'tt23v'::regclass and ev_type = '1'; + pg_get_ruledef +----------------------------------------------------------------- + CREATE RULE "_RETURN" AS + + ON SELECT TO tt23v DO INSTEAD SELECT int8_tbl.q1 AS col_a,+ + int8_tbl.q2 AS col_b + + FROM int8_tbl + + UNION + + SELECT 42 AS col_a, + + 43 AS col_b; +(1 row) + -- clean up all the random objects we made above set client_min_messages = warning; DROP SCHEMA temp_view_test CASCADE; diff --git a/src/test/regress/sql/create_view.sql b/src/test/regress/sql/create_view.sql index 6e7463cf14e..04941671dd5 100644 --- a/src/test/regress/sql/create_view.sql +++ b/src/test/regress/sql/create_view.sql @@ -569,6 +569,17 @@ create view tt22v as select * from tt5 natural left join tt6; select pg_get_viewdef('tt22v', true); +-- check handling of views with immediately-renamed columns + +create view tt23v (col_a, col_b) as +select q1 as other_name1, q2 as other_name2 from int8_tbl +union +select 42, 43; + +select pg_get_viewdef('tt23v', true); +select pg_get_ruledef(oid, true) from pg_rewrite + where ev_class = 'tt23v'::regclass and ev_type = '1'; + -- clean up all the random objects we made above set client_min_messages = warning; DROP SCHEMA temp_view_test CASCADE; |
