From 9659ff870a7fdd31818e12388694383be4b8bfab Mon Sep 17 00:00:00 2001 From: luozihao <1165977584@qq.com> Date: Wed, 23 Nov 2022 21:08:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Ddump=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bin/pg_dump/pg_dump.cpp | 3 +- .../regress/input/view_definer_test.source | 13 +++++++ .../regress/output/view_definer_test.source | 38 +++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/src/bin/pg_dump/pg_dump.cpp b/src/bin/pg_dump/pg_dump.cpp index 6a6aaee61..709039520 100644 --- a/src/bin/pg_dump/pg_dump.cpp +++ b/src/bin/pg_dump/pg_dump.cpp @@ -18091,7 +18091,8 @@ static void dumpViewSchema( /* set definer for CREATE VIEW statement */ appendPQExpBuffer(q, "CREATE "); - if (tbinfo->rolname != NULL && strlen(tbinfo->rolname) > 0) { + if ((gdatcompatibility != NULL) && strcmp(gdatcompatibility, B_FORMAT) == 0 && + tbinfo->rolname != NULL && strlen(tbinfo->rolname) > 0) { appendPQExpBuffer(q, " DEFINER = %s ", tbinfo->rolname); } appendPQExpBuffer(q, " VIEW %s(%s)", fmtId(tbinfo->dobj.name), schemainfo); diff --git a/src/test/regress/input/view_definer_test.source b/src/test/regress/input/view_definer_test.source index 77dce4fe4..a3eb63dad 100644 --- a/src/test/regress/input/view_definer_test.source +++ b/src/test/regress/input/view_definer_test.source @@ -45,8 +45,21 @@ SELECT c.relname as view_name, u.usename as rolname FROM pg_class c, pg_user u W RESET ROLE; +create database test_1; +\c test_1 +create table startwith_t(id int, level int, connect_by_isleaf int, connect_by_iscycle int); +create view startwith_v as select id, connect_by_isleaf as level, level as connect_by_isleaf from startwith_t; + +\! @abs_bindir@/gs_dump test_1 -p @portstring@ -f @abs_bindir@/dump_postgres.sql +drop database if exists test_2; +create database test_2; +\! @abs_bindir@/gsql -d test_2 -p @portstring@ -f @abs_bindir@/dump_postgres.sql +\! @abs_bindir@/gsql -d test_2 -p @portstring@ -c "select * from startwith_v;" + \c regression drop database test_db; +drop database test_1; +drop database test_2; DROP USER test_user; DROP USER test_user2; DROP USER root_test CASCADE; diff --git a/src/test/regress/output/view_definer_test.source b/src/test/regress/output/view_definer_test.source index 0439629e5..40dd11bb3 100644 --- a/src/test/regress/output/view_definer_test.source +++ b/src/test/regress/output/view_definer_test.source @@ -101,8 +101,46 @@ SELECT c.relname as view_name, u.usename as rolname FROM pg_class c, pg_user u W (3 rows) RESET ROLE; +create database test_1; +\c test_1 +create table startwith_t(id int, level int, connect_by_isleaf int, connect_by_iscycle int); +create view startwith_v as select id, connect_by_isleaf as level, level as connect_by_isleaf from startwith_t; +\! @abs_bindir@/gs_dump test_1 -p @portstring@ -f @abs_bindir@/dump_postgres.sql +--?.* +--?.* +--?.* +--?.* +drop database if exists test_2; +NOTICE: database "test_2" does not exist, skipping +create database test_2; +\! @abs_bindir@/gsql -d test_2 -p @portstring@ -f @abs_bindir@/dump_postgres.sql +SET +SET +SET +SET +SET +SET +SET +SET +SET +CREATE TABLE +ALTER TABLE +CREATE VIEW +ALTER VIEW +REVOKE +REVOKE +GRANT +GRANT +--?.* +\! @abs_bindir@/gsql -d test_2 -p @portstring@ -c "select * from startwith_v;" + id | level | connect_by_isleaf +----+-------+------------------- +(0 rows) + \c regression drop database test_db; +drop database test_1; +drop database test_2; DROP USER test_user; DROP USER test_user2; DROP USER root_test CASCADE;