diff --git a/src/backend/distributed/commands/table.c b/src/backend/distributed/commands/table.c index b01d6d9c7..89f90ea3e 100644 --- a/src/backend/distributed/commands/table.c +++ b/src/backend/distributed/commands/table.c @@ -264,7 +264,10 @@ PostprocessAlterTableSchemaStmt(Node *node, const char *queryString) AlterObjectSchemaStmt *stmt = castNode(AlterObjectSchemaStmt, node); 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)) { @@ -1479,7 +1482,7 @@ AlterTableSchemaStmtObjectAddress(Node *node, bool missing_ok) if (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); } else diff --git a/src/test/regress/expected/multi_schema_support.out b/src/test/regress/expected/multi_schema_support.out index dae406c50..7bfda583b 100644 --- a/src/test/regress/expected/multi_schema_support.out +++ b/src/test/regress/expected/multi_schema_support.out @@ -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 ALTER TABLE existing_schema.table_set_schema SET SCHEMA non_existent_schema; 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; NOTICE: drop cascades to table existing_schema.table_set_schema -- test ALTER TABLE SET SCHEMA with interesting names diff --git a/src/test/regress/sql/multi_schema_support.sql b/src/test/regress/sql/multi_schema_support.sql index b08d59849..31ee16780 100644 --- a/src/test/regress/sql/multi_schema_support.sql +++ b/src/test/regress/sql/multi_schema_support.sql @@ -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 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;