From a274ffcb51a717cbfff914ab7f4b0fafe5f3ce5c Mon Sep 17 00:00:00 2001 From: gindibay Date: Fri, 13 Oct 2023 01:36:01 +0300 Subject: [PATCH] Adds If exists statement for drop database --- src/backend/distributed/deparser/deparse_database_stmts.c | 4 +++- .../regress/expected/create_drop_database_propagation.out | 6 +++--- src/test/regress/sql/create_drop_database_propagation.sql | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/backend/distributed/deparser/deparse_database_stmts.c b/src/backend/distributed/deparser/deparse_database_stmts.c index 5365f072d..7c7544694 100644 --- a/src/backend/distributed/deparser/deparse_database_stmts.c +++ b/src/backend/distributed/deparser/deparse_database_stmts.c @@ -259,8 +259,10 @@ DeparseCreateDatabaseStmt(Node *node) static void AppendDropDatabaseStmt(StringInfo buf, DropdbStmt *stmt) { + char *if_exists_statement = stmt->missing_ok ? "IF EXISTS" : ""; appendStringInfo(buf, - "DROP DATABASE %s", + "DROP DATABASE %s %s", + if_exists_statement, quote_identifier(stmt->dbname)); DefElem *option = NULL; diff --git a/src/test/regress/expected/create_drop_database_propagation.out b/src/test/regress/expected/create_drop_database_propagation.out index be85e50c0..37829a6ee 100644 --- a/src/test/regress/expected/create_drop_database_propagation.out +++ b/src/test/regress/expected/create_drop_database_propagation.out @@ -112,10 +112,10 @@ DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx NOTICE: issuing SELECT pg_catalog.citus_internal_database_command('CREATE DATABASE "mydatabase#1''2"') DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx set citus.grep_remote_commands = '%DROP DATABASE%'; -drop database "mydatabase#1'2"; -NOTICE: issuing SELECT pg_catalog.citus_internal_database_command('DROP DATABASE "mydatabase#1''2"') +drop database if exists "mydatabase#1'2"; +NOTICE: issuing SELECT pg_catalog.citus_internal_database_command('DROP DATABASE IF EXISTS "mydatabase#1''2"') DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx -NOTICE: issuing SELECT pg_catalog.citus_internal_database_command('DROP DATABASE "mydatabase#1''2"') +NOTICE: issuing SELECT pg_catalog.citus_internal_database_command('DROP DATABASE IF EXISTS "mydatabase#1''2"') DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx --clean up resources created by this test drop tablespace create_drop_db_tablespace; diff --git a/src/test/regress/sql/create_drop_database_propagation.sql b/src/test/regress/sql/create_drop_database_propagation.sql index 5e2166f77..d84654054 100644 --- a/src/test/regress/sql/create_drop_database_propagation.sql +++ b/src/test/regress/sql/create_drop_database_propagation.sql @@ -102,7 +102,7 @@ set citus.grep_remote_commands = '%CREATE DATABASE%'; create database "mydatabase#1'2"; set citus.grep_remote_commands = '%DROP DATABASE%'; -drop database "mydatabase#1'2"; +drop database if exists "mydatabase#1'2"; --clean up resources created by this test