| From: | kou(at)clear-code(dot)com | 
|---|---|
| To: | pgsql-bugs(at)postgresql(dot)org | 
| Subject: | BUG #14160: DROP ACCESS METHOD IF EXISTS isn't implemented | 
| Date: | 2016-05-27 07:04:33 | 
| Message-ID: | 20160527070433.19424.81712@wrigleys.postgresql.org | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-bugs | 
The following bug has been logged on the website:
Bug reference:      14160
Logged by:          Kouhei Sutou
Email address:      kou(at)clear-code(dot)com
PostgreSQL version: 9.6beta1
Operating system:   Debian GNU/Linux sid
Description:        
"DROP ACCESS METHOD IF EXISTS" against nonexistent access method returns an
error:
----
postgres=# DROP ACCESS METHOD IF EXISTS nonexistent;
ERROR:  unexpected object type (0)
----
Here is an implementation:
----
From a7b32f3ab3fed3a5334d7ca7d8e31edc474dc26e Mon Sep 17 00:00:00 2001
From: Kouhei Sutou <kou(at)clear-code(dot)com>
Date: Fri, 27 May 2016 16:03:11 +0900
Subject: [PATCH] Implement DROP ACCESS METHOD IF EXISTS against
nonexistent
 access method
---
 src/backend/commands/dropcmds.c              | 4 ++++
 src/test/regress/expected/drop_if_exists.out | 5 +++++
 src/test/regress/sql/drop_if_exists.sql      | 4 ++++
 3 files changed, 13 insertions(+)
diff --git a/src/backend/commands/dropcmds.c
b/src/backend/commands/dropcmds.c
index 522027a..d9f7861 100644
--- a/src/backend/commands/dropcmds.c
+++ b/src/backend/commands/dropcmds.c
@@ -437,6 +437,10 @@ does_not_exist_skipping(ObjectType objtype, List
*objname, List *objargs)
 				}
 			}
 			break;
+		case OBJECT_ACCESS_METHOD:
+			msg = gettext_noop("access method \"%s\" does not exist, skipping");
+			name = NameListToString(objname);
+			break;
 		default:
 			elog(ERROR, "unexpected object type (%d)", (int) objtype);
 			break;
diff --git a/src/test/regress/expected/drop_if_exists.out
b/src/test/regress/expected/drop_if_exists.out
index 6910b62..9cda96b 100644
--- a/src/test/regress/expected/drop_if_exists.out
+++ b/src/test/regress/expected/drop_if_exists.out
@@ -227,6 +227,11 @@ DROP OPERATOR FAMILY test_operator_family USING
no_such_am;
 ERROR:  access method "no_such_am" does not exist
 DROP OPERATOR FAMILY IF EXISTS test_operator_family USING no_such_am;
 ERROR:  access method "no_such_am" does not exist
+-- access method
+DROP ACCESS METHOD no_such_am;
+ERROR:  access method "no_such_am" does not exist
+DROP ACCESS METHOD IF EXISTS no_such_am;
+NOTICE:  access method "no_such_am" does not exist, skipping
 -- drop the table
 DROP TABLE IF EXISTS test_exists;
 DROP TABLE test_exists;
diff --git a/src/test/regress/sql/drop_if_exists.sql
b/src/test/regress/sql/drop_if_exists.sql
index 03547cc..4ff0450 100644
--- a/src/test/regress/sql/drop_if_exists.sql
+++ b/src/test/regress/sql/drop_if_exists.sql
@@ -227,6 +227,10 @@ DROP OPERATOR FAMILY IF EXISTS test_operator_family
USING btree;
 DROP OPERATOR FAMILY test_operator_family USING no_such_am;
 DROP OPERATOR FAMILY IF EXISTS test_operator_family USING no_such_am;
 
+-- access method
+DROP ACCESS METHOD no_such_am;
+DROP ACCESS METHOD IF EXISTS no_such_am;
+
 -- drop the table
 
 DROP TABLE IF EXISTS test_exists;
-- 
2.8.1
----
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Michael Paquier | 2016-05-27 07:48:31 | Re: BUG #14160: DROP ACCESS METHOD IF EXISTS isn't implemented | 
| Previous Message | Andres Freund | 2016-05-27 06:10:47 | Re: BUG #14159: PostgreSQL 9.6 parallel scan consume very high mutex lock |