diff --git a/src/backend/distributed/executor/multi_utility.c b/src/backend/distributed/executor/multi_utility.c index ccfe3135a..8b895b551 100644 --- a/src/backend/distributed/executor/multi_utility.c +++ b/src/backend/distributed/executor/multi_utility.c @@ -549,11 +549,15 @@ multi_ProcessUtility(PlannedStmt *pstmt, */ if (IsA(parsetree, DropdbStmt)) { + const bool missingOK = true; DropdbStmt *dropDbStatement = (DropdbStmt *) parsetree; char *dbname = dropDbStatement->dbname; - Oid databaseOid = get_database_oid(dbname, false); + Oid databaseOid = get_database_oid(dbname, missingOK); - StopMaintenanceDaemon(databaseOid); + if (OidIsValid(databaseOid)) + { + StopMaintenanceDaemon(databaseOid); + } } /* set user if needed and go ahead and run local utility using standard hook */ diff --git a/src/test/regress/expected/multi_utility_statements.out b/src/test/regress/expected/multi_utility_statements.out index ad68fa8f2..5f19ef09d 100644 --- a/src/test/regress/expected/multi_utility_statements.out +++ b/src/test/regress/expected/multi_utility_statements.out @@ -268,3 +268,10 @@ FETCH BACKWARD noHoldCursor; COMMIT; FETCH ABSOLUTE 5 FROM noHoldCursor; ERROR: cursor "noholdcursor" does not exist +-- Test we don't throw an error for DROP IF EXISTS +DROP DATABASE IF EXISTS not_existing_database; +NOTICE: database "not_existing_database" does not exist, skipping +DROP TABLE IF EXISTS not_existing_table; +NOTICE: table "not_existing_table" does not exist, skipping +DROP SCHEMA IF EXISTS not_existing_schema; +NOTICE: schema "not_existing_schema" does not exist, skipping diff --git a/src/test/regress/sql/multi_utility_statements.sql b/src/test/regress/sql/multi_utility_statements.sql index d3ab57950..fb4e7ce82 100644 --- a/src/test/regress/sql/multi_utility_statements.sql +++ b/src/test/regress/sql/multi_utility_statements.sql @@ -146,3 +146,8 @@ FETCH ABSOLUTE 5 FROM noHoldCursor; FETCH BACKWARD noHoldCursor; COMMIT; FETCH ABSOLUTE 5 FROM noHoldCursor; + +-- Test we don't throw an error for DROP IF EXISTS +DROP DATABASE IF EXISTS not_existing_database; +DROP TABLE IF EXISTS not_existing_table; +DROP SCHEMA IF EXISTS not_existing_schema;