From e9f89ed651e41b5b782b90330a403c5bb647b6e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20Ozan=20Akg=C3=BCl?= Date: Thu, 23 Jul 2020 18:01:21 +0300 Subject: [PATCH] Fixes the non existing table bug (#4058) --- src/backend/distributed/commands/table.c | 7 +++++-- .../regress/expected/multi_schema_support.out | 19 +++++++++++++++++++ src/test/regress/sql/multi_schema_support.sql | 12 ++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/backend/distributed/commands/table.c b/src/backend/distributed/commands/table.c index 6c9fec88d..f13f512ff 100644 --- a/src/backend/distributed/commands/table.c +++ b/src/backend/distributed/commands/table.c @@ -269,7 +269,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() || !IsCitusTable(tableAddress.objectId)) { @@ -1481,7 +1484,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 8126d03ba..53d34abce 100644 --- a/src/test/regress/expected/multi_schema_support.out +++ b/src/test/regress/expected/multi_schema_support.out @@ -1196,6 +1196,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 698e8111f..3c41aae02 100644 --- a/src/test/regress/sql/multi_schema_support.sql +++ b/src/test/regress/sql/multi_schema_support.sql @@ -842,6 +842,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;