Fixes the non existing table bug (#4058)

(cherry picked from commit e9f89ed651)
release-9.2
Halil Ozan Akgül 2020-07-23 18:01:21 +03:00 committed by Halil Ozan Akgul
parent 683279cc36
commit b504b749a6
3 changed files with 36 additions and 2 deletions

View File

@ -264,7 +264,10 @@ PostprocessAlterTableSchemaStmt(Node *node, const char *queryString)
AlterObjectSchemaStmt *stmt = castNode(AlterObjectSchemaStmt, node); AlterObjectSchemaStmt *stmt = castNode(AlterObjectSchemaStmt, node);
Assert(stmt->objectType == OBJECT_TABLE); Assert(stmt->objectType == OBJECT_TABLE);
ObjectAddress tableAddress = GetObjectAddressFromParseTree((Node *) stmt, false); /*
* We will let Postgres deal with missing_ok
*/
ObjectAddress tableAddress = GetObjectAddressFromParseTree((Node *) stmt, true);
if (!ShouldPropagate() || !IsDistributedTable(tableAddress.objectId)) if (!ShouldPropagate() || !IsDistributedTable(tableAddress.objectId))
{ {
@ -1479,7 +1482,7 @@ AlterTableSchemaStmtObjectAddress(Node *node, bool missing_ok)
if (stmt->relation->schemaname) if (stmt->relation->schemaname)
{ {
const char *schemaName = stmt->relation->schemaname; const char *schemaName = stmt->relation->schemaname;
Oid schemaOid = get_namespace_oid(schemaName, false); Oid schemaOid = get_namespace_oid(schemaName, missing_ok);
tableOid = get_relname_relid(tableName, schemaOid); tableOid = get_relname_relid(tableName, schemaOid);
} }
else else

View File

@ -1197,6 +1197,25 @@ ALTER TABLE existing_schema.non_existent_table SET SCHEMA non_existent_schema;
ERROR: relation "existing_schema.non_existent_table" does not exist ERROR: relation "existing_schema.non_existent_table" does not exist
ALTER TABLE existing_schema.table_set_schema SET SCHEMA non_existent_schema; ALTER TABLE existing_schema.table_set_schema SET SCHEMA non_existent_schema;
ERROR: schema "non_existent_schema" does not exist ERROR: schema "non_existent_schema" does not exist
-- test ALTER TABLE IF EXISTS SET SCHEMA with nonexisting schemas and table
ALTER TABLE IF EXISTS non_existent_schema.table_set_schema SET SCHEMA another_existing_schema;
NOTICE: relation "table_set_schema" does not exist, skipping
ALTER TABLE IF EXISTS non_existent_schema.non_existent_table SET SCHEMA another_existing_schema;
NOTICE: relation "non_existent_table" does not exist, skipping
ALTER TABLE IF EXISTS non_existent_schema.table_set_schema SET SCHEMA another_non_existent_schema;
NOTICE: relation "table_set_schema" does not exist, skipping
ALTER TABLE IF EXISTS non_existent_schema.non_existent_table SET SCHEMA another_non_existent_schema;
NOTICE: relation "non_existent_table" does not exist, skipping
ALTER TABLE IF EXISTS existing_schema.non_existent_table SET SCHEMA another_existing_schema;
NOTICE: relation "non_existent_table" does not exist, skipping
ALTER TABLE IF EXISTS existing_schema.non_existent_table SET SCHEMA non_existent_schema;
NOTICE: relation "non_existent_table" does not exist, skipping
ALTER TABLE IF EXISTS existing_schema.table_set_schema SET SCHEMA non_existent_schema;
ERROR: schema "non_existent_schema" does not exist
ALTER TABLE IF EXISTS non_existent_table SET SCHEMA another_existing_schema;
NOTICE: relation "non_existent_table" does not exist, skipping
ALTER TABLE IF EXISTS non_existent_table SET SCHEMA non_existent_schema;
NOTICE: relation "non_existent_table" does not exist, skipping
DROP SCHEMA existing_schema, another_existing_schema CASCADE; DROP SCHEMA existing_schema, another_existing_schema CASCADE;
NOTICE: drop cascades to table existing_schema.table_set_schema NOTICE: drop cascades to table existing_schema.table_set_schema
-- test ALTER TABLE SET SCHEMA with interesting names -- test ALTER TABLE SET SCHEMA with interesting names

View File

@ -843,6 +843,18 @@ ALTER TABLE non_existent_schema.non_existent_table SET SCHEMA another_non_existe
ALTER TABLE existing_schema.non_existent_table SET SCHEMA another_existing_schema; ALTER TABLE existing_schema.non_existent_table SET SCHEMA another_existing_schema;
ALTER TABLE existing_schema.non_existent_table SET SCHEMA non_existent_schema; ALTER TABLE existing_schema.non_existent_table SET SCHEMA non_existent_schema;
ALTER TABLE existing_schema.table_set_schema SET SCHEMA non_existent_schema; ALTER TABLE existing_schema.table_set_schema SET SCHEMA non_existent_schema;
-- test ALTER TABLE IF EXISTS SET SCHEMA with nonexisting schemas and table
ALTER TABLE IF EXISTS non_existent_schema.table_set_schema SET SCHEMA another_existing_schema;
ALTER TABLE IF EXISTS non_existent_schema.non_existent_table SET SCHEMA another_existing_schema;
ALTER TABLE IF EXISTS non_existent_schema.table_set_schema SET SCHEMA another_non_existent_schema;
ALTER TABLE IF EXISTS non_existent_schema.non_existent_table SET SCHEMA another_non_existent_schema;
ALTER TABLE IF EXISTS existing_schema.non_existent_table SET SCHEMA another_existing_schema;
ALTER TABLE IF EXISTS existing_schema.non_existent_table SET SCHEMA non_existent_schema;
ALTER TABLE IF EXISTS existing_schema.table_set_schema SET SCHEMA non_existent_schema;
ALTER TABLE IF EXISTS non_existent_table SET SCHEMA another_existing_schema;
ALTER TABLE IF EXISTS non_existent_table SET SCHEMA non_existent_schema;
DROP SCHEMA existing_schema, another_existing_schema CASCADE; DROP SCHEMA existing_schema, another_existing_schema CASCADE;