Fix DROP ACCESS METHOD IF EXISTS.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 27 May 2016 15:03:18 +0000 (11:03 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 27 May 2016 15:03:18 +0000 (11:03 -0400)
The IF EXISTS option was documented, and implemented in the grammar, but
it didn't actually work for lack of support in does_not_exist_skipping().
Per bug #14160.

Report and patch by Kouhei Sutou

Report: <20160527070433.19424.81712@wrigleys.postgresql.org>

src/backend/commands/dropcmds.c
src/test/regress/expected/drop_if_exists.out
src/test/regress/sql/drop_if_exists.sql

index 522027ac3eec61c0d7635984652663669fb92b88..61ff8f2190d4dad1364b9e50ab485564af78ecbe 100644 (file)
@@ -262,6 +262,10 @@ does_not_exist_skipping(ObjectType objtype, List *objname, List *objargs)
 
        switch (objtype)
        {
+               case OBJECT_ACCESS_METHOD:
+                       msg = gettext_noop("access method \"%s\" does not exist, skipping");
+                       name = NameListToString(objname);
+                       break;
                case OBJECT_TYPE:
                case OBJECT_DOMAIN:
                        {
@@ -438,7 +442,7 @@ does_not_exist_skipping(ObjectType objtype, List *objname, List *objargs)
                        }
                        break;
                default:
-                       elog(ERROR, "unexpected object type (%d)", (int) objtype);
+                       elog(ERROR, "unrecognized object type: %d", (int) objtype);
                        break;
        }
 
index 6910b627c1538d16f86c2daa9981c4a5c5ba5c75..9cda96b6dea9ad89053d890905f0ddc22165f459 100644 (file)
@@ -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;
index 03547ccae7a627b2068e738e5757b5f9d8ef0941..4ff045073113bb4490ee7979caba16cd5d8409eb 100644 (file)
@@ -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;