Validate schema name when create.

This commit is contained in:
TotaJ
2021-01-18 20:08:40 +08:00
parent 39f647127f
commit 9444ff97c1
3 changed files with 17 additions and 1 deletions

View File

@ -141,7 +141,10 @@ void CreateSchemaCommand(CreateSchemaStmt* stmt, const char* queryString)
//@Temp Table. We allow datanode to create pg_temp namespace to enable create namespace stmt by CN to execute on
// DN
if (!g_instance.attr.attr_common.allowSystemTableMods && !u_sess->attr.attr_common.IsInplaceUpgrade &&
IsReservedName(schemaName) && !IS_PGXC_DATANODE)
#ifdef ENABLE_MULTIPLE_NODES
!IS_PGXC_DATANODE &&
#endif
IsReservedName(schemaName))
ereport(ERROR,
(errcode(ERRCODE_RESERVED_NAME),
errmsg("unacceptable schema name \"%s\"", schemaName),

View File

@ -17,6 +17,14 @@ create table abc(
b int
);
NOTICE: CREATE TABLE will create implicit sequence "abc_a_seq" for serial column "abc.a"
--illegal schema name, start with 'pg_'
create schema pg_error_schema;
ERROR: unacceptable schema name "pg_error_schema"
DETAIL: The prefix "pg_" is reserved for system schemas.
--create user will create a schema which name is same as username, so it is also illegal.
create user pg_error_username password 'test-1234';
ERROR: unacceptable user name: fail to create same name schema for user "pg_error_username"
DETAIL: The prefix "pg_" is reserved for system schemas.
drop role samedb_schema_cn_role_02_001;
drop schema test_ns_schema_1 cascade;
NOTICE: drop cascades to 2 other objects

View File

@ -24,6 +24,11 @@ create table abc(
b int
);
--illegal schema name, start with 'pg_'
create schema pg_error_schema;
--create user will create a schema which name is same as username, so it is also illegal.
create user pg_error_username password 'test-1234';
drop role samedb_schema_cn_role_02_001;
drop schema test_ns_schema_1 cascade;