Throw error for ALTER TABLE RESET of an invalid option
authorBruce Momjian <bruce@momjian.us>
Mon, 25 Aug 2014 21:06:40 +0000 (17:06 -0400)
committerBruce Momjian <bruce@momjian.us>
Mon, 25 Aug 2014 21:06:40 +0000 (17:06 -0400)
Also adjust pg_upgrade to not use this method for optional TOAST table
creation.

Patch by Fabrízio de Royes Mello

contrib/pg_upgrade/dump.c
src/backend/access/common/reloptions.c

index e623a2263277262fd15a52671df4ae2f89431907..29a68c07a2d0f5d70a40487b69af76c31ef59954 100644 (file)
@@ -115,6 +115,10 @@ optionally_create_toast_tables(void)
                                "c.relkind IN ('r', 'm') AND "
                                "c.reltoastrelid = 0");
 
+       /* Suppress NOTICE output from non-existant constraints */
+       PQclear(executeQueryOrDie(conn, "SET client_min_messages = warning;"));
+       PQclear(executeQueryOrDie(conn, "SET log_min_messages = warning;"));
+
        ntups = PQntuples(res);
        i_nspname = PQfnumber(res, "nspname");
        i_relname = PQfnumber(res, "relname");
@@ -125,13 +129,16 @@ optionally_create_toast_tables(void)
                    OPTIONALLY_CREATE_TOAST_OID));
 
            /* dummy command that also triggers check for required TOAST table */
-           PQclear(executeQueryOrDie(conn, "ALTER TABLE %s.%s RESET (binary_upgrade_dummy_option);",
+           PQclear(executeQueryOrDie(conn, "ALTER TABLE %s.%s DROP CONSTRAINT IF EXISTS binary_upgrade_dummy_constraint;",
                    quote_identifier(PQgetvalue(res, rowno, i_nspname)),
                    quote_identifier(PQgetvalue(res, rowno, i_relname))));
        }
 
        PQclear(res);
 
+       PQclear(executeQueryOrDie(conn, "RESET client_min_messages;"));
+       PQclear(executeQueryOrDie(conn, "RESET log_min_messages;"));
+
        PQfinish(conn);
    }
 
index e0b81b9eb5139e8db3c4de25ca3bec7ffaab21bb..97a4e227a3bc1c634e5ff283d07cfab7c0443da4 100644 (file)
@@ -307,6 +307,8 @@ static void initialize_reloptions(void);
 static void parse_one_reloption(relopt_value *option, char *text_str,
                    int text_len, bool validate);
 
+static bool is_valid_reloption(char *name);
+
 /*
  * initialize_reloptions
  *     initialization routine, must be called before parsing
@@ -381,6 +383,25 @@ initialize_reloptions(void)
    need_initialization = false;
 }
 
+/*
+ * is_valid_reloption
+ *     check if a reloption exists
+ *
+ */
+static bool
+is_valid_reloption(char *name)
+{
+   int i;
+
+   for (i = 0; relOpts[i]; i++)
+   {
+       if (pg_strcasecmp(relOpts[i]->name, name) == 0)
+           return true;
+   }
+
+   return false;
+}
+
 /*
  * add_reloption_kind
  *     Create a new relopt_kind value, to be used in custom reloptions by
@@ -672,6 +693,11 @@ transformRelOptions(Datum oldOptions, List *defList, char *namspace,
 
        if (isReset)
        {
+           if (!is_valid_reloption(def->defname))
+               ereport(ERROR,
+                       (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+                        errmsg("unrecognized parameter \"%s\"", def->defname)));
+
            if (def->arg != NULL)
                ereport(ERROR,
                        (errcode(ERRCODE_SYNTAX_ERROR),