BUG #14160: DROP ACCESS METHOD IF EXISTS isn't implemented

Started by Sutou Kouheialmost 10 years ago3 messagesbugs
Jump to latest
#1Sutou Kouhei
kou@clear-code.com

The following bug has been logged on the website:

Bug reference: 14160
Logged by: Kouhei Sutou
Email address: kou@clear-code.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@clear-code.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
----

--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

#2Michael Paquier
michael@paquier.xyz
In reply to: Sutou Kouhei (#1)
Re: BUG #14160: DROP ACCESS METHOD IF EXISTS isn't implemented

On Fri, May 27, 2016 at 4:04 PM, <kou@clear-code.com> wrote:

"DROP ACCESS METHOD IF EXISTS" against nonexistent access method returns an
error:

----
postgres=# DROP ACCESS METHOD IF EXISTS nonexistent;
ERROR: unexpected object type (0)
----

Good catch. The documents are stating that it is implemented though
that's not the case.
--
Michael

--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Sutou Kouhei (#1)
Re: BUG #14160: DROP ACCESS METHOD IF EXISTS isn't implemented

kou@clear-code.com writes:

"DROP ACCESS METHOD IF EXISTS" against nonexistent access method returns an
error:

Pushed, thanks!

regards, tom lane

--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs