[bugfix] comment on table support table and view for A compatibilty

This commit is contained in:
douxin
2024-06-06 15:08:51 +08:00
committed by yaoxin
parent 64d1270895
commit 25e1ef81d7
4 changed files with 166 additions and 2 deletions

View File

@ -131,6 +131,19 @@ ObjectAddress CommentObject(CommentStmt* stmt)
}
}
/*
* For only A compatibility, comment on table support table and view object
*/
if (DB_IS_CMPT(A_FORMAT) && stmt->objtype == OBJECT_TABLE) {
Relation rel = relation_openrv_extended(makeRangeVarFromNameList(stmt->objname), ShareUpdateExclusiveLock, false);
if (rel) {
if(rel->rd_rel->relkind == RELKIND_VIEW) {
stmt->objtype = OBJECT_VIEW;
}
RelationClose(rel);
}
}
/*
* Translate the parser representation that identifies this object into an
* ObjectAddress. get_object_address() will throw an error if the object
@ -463,4 +476,4 @@ void CreateNonColumnComment(Oid oid, List *options, Oid objectType)
break;
}
}
}
}

View File

@ -0,0 +1,79 @@
--
-- comment on table
--
-- A compatibility
create database comment_table_testa with dbcompatibility = 'A';
\c comment_table_testa
create table t1(id int);
create index index1 on t1(id);
create view t1_v as select * from t1;
comment on table t1 is 'table t1';
comment on table t1_v is 'table t1 view';
comment on table index1 is 'table t1 index';
ERROR: "index1" is not a table
comment on index index1 is 'table t1 index';
drop view t1_v;
drop table t1;
create schema test_comment_schema;
create table test_comment_schema.t1(id int);
create index idx1 on test_comment_schema.t1(id);
create view test_comment_schema.t1_v as select * from test_comment_schema.t1;
comment on table test_comment_schema.t1 is 'table t1';
comment on table test_comment_schema.t1_v is 'table t1 view';
comment on table idx1 is 'table t1 index';
ERROR: relation "idx1" does not exist
comment on table test_comment_schema.idx1 is 'table t1 index';
ERROR: "idx1" is not a table
comment on index test_comment_schema.idx1 is 'table t1 index';
-- not exist
comment on table t2 is 'table t2';
ERROR: relation "t2" does not exist
comment on table test_comment_schema.t2 is 'table test_comment_schema.t2';
ERROR: relation "test_comment_schema.t2" does not exist
comment on table schema1.t2 is 'table schema1.t2';
ERROR: schema "schema1" does not exist
drop schema test_comment_schema cascade;
NOTICE: drop cascades to 2 other objects
DETAIL: drop cascades to table test_comment_schema.t1
drop cascades to view test_comment_schema.t1_v
\c postgres
drop database comment_table_testa;
-- B compatibility
create database comment_table_testb with dbcompatibility = 'B';
\c comment_table_testb
create table t1(id int);
create index index1 on t1(id);
create view t1_v as select * from t1;
comment on table t1 is 'table t1';
comment on table t1_v is 'table t1 view';
ERROR: "t1_v" is not a table
comment on table index1 is 'table t1 index';
ERROR: "index1" is not a table
comment on index index1 is 'table t1 index';
drop view t1_v;
drop table t1;
create schema test_comment_schema;
create table test_comment_schema.t1(id int);
create index idx1 on test_comment_schema.t1(id);
create view test_comment_schema.t1_v as select * from test_comment_schema.t1;
comment on table test_comment_schema.t1 is 'table t1';
comment on table test_comment_schema.t1_v is 'table t1 view';
ERROR: "t1_v" is not a table
comment on table idx1 is 'table t1 index';
ERROR: relation "idx1" does not exist
comment on table test_comment_schema.idx1 is 'table t1 index';
ERROR: "idx1" is not a table
comment on index test_comment_schema.idx1 is 'table t1 index';
-- not exist
comment on table t2 is 'table t2';
ERROR: relation "t2" does not exist
comment on table test_comment_schema.t2 is 'table test_comment_schema.t2';
ERROR: relation "test_comment_schema.t2" does not exist
comment on table schema1.t2 is 'table schema1.t2';
ERROR: schema "schema1" does not exist
drop schema test_comment_schema cascade;
NOTICE: drop cascades to 2 other objects
DETAIL: drop cascades to table test_comment_schema.t1
drop cascades to view test_comment_schema.t1_v
\c postgres
drop database comment_table_testb;

View File

@ -427,7 +427,7 @@ test: create_seg_table
# ----------
#test: hw_hashagg_start
test: create_misc
test: create_view1 create_view2 create_view3 create_view4 create_view5
test: create_view1 create_view2 create_view3 create_view4 create_view5 comment_table
#test: int8#
#dupliacated select int8

View File

@ -0,0 +1,72 @@
--
-- comment on table
--
-- A compatibility
create database comment_table_testa with dbcompatibility = 'A';
\c comment_table_testa
create table t1(id int);
create index index1 on t1(id);
create view t1_v as select * from t1;
comment on table t1 is 'table t1';
comment on table t1_v is 'table t1 view';
comment on table index1 is 'table t1 index';
comment on index index1 is 'table t1 index';
drop view t1_v;
drop table t1;
create schema test_comment_schema;
create table test_comment_schema.t1(id int);
create index idx1 on test_comment_schema.t1(id);
create view test_comment_schema.t1_v as select * from test_comment_schema.t1;
comment on table test_comment_schema.t1 is 'table t1';
comment on table test_comment_schema.t1_v is 'table t1 view';
comment on table idx1 is 'table t1 index';
comment on table test_comment_schema.idx1 is 'table t1 index';
comment on index test_comment_schema.idx1 is 'table t1 index';
-- not exist
comment on table t2 is 'table t2';
comment on table test_comment_schema.t2 is 'table test_comment_schema.t2';
comment on table schema1.t2 is 'table schema1.t2';
drop schema test_comment_schema cascade;
\c postgres
drop database comment_table_testa;
-- B compatibility
create database comment_table_testb with dbcompatibility = 'B';
\c comment_table_testb
create table t1(id int);
create index index1 on t1(id);
create view t1_v as select * from t1;
comment on table t1 is 'table t1';
comment on table t1_v is 'table t1 view';
comment on table index1 is 'table t1 index';
comment on index index1 is 'table t1 index';
drop view t1_v;
drop table t1;
create schema test_comment_schema;
create table test_comment_schema.t1(id int);
create index idx1 on test_comment_schema.t1(id);
create view test_comment_schema.t1_v as select * from test_comment_schema.t1;
comment on table test_comment_schema.t1 is 'table t1';
comment on table test_comment_schema.t1_v is 'table t1 view';
comment on table idx1 is 'table t1 index';
comment on table test_comment_schema.idx1 is 'table t1 index';
comment on index test_comment_schema.idx1 is 'table t1 index';
-- not exist
comment on table t2 is 'table t2';
comment on table test_comment_schema.t2 is 'table test_comment_schema.t2';
comment on table schema1.t2 is 'table schema1.t2';
drop schema test_comment_schema cascade;
\c postgres
drop database comment_table_testb;