On Thu, Mar 13, 2014 at 10:22 AM, Robert Haas <robertmh...@gmail.com> wrote:
>
> On Wed, Mar 12, 2014 at 11:11 PM, Fabrízio de Royes Mello
> <fabriziome...@gmail.com> wrote:
> > Hi all,
> >
> > Shouldn't the "ALTER" statements below raise an exception?
> >
> > fabrizio=# CREATE TABLE foo(bar SERIAL PRIMARY KEY);
> > CREATE TABLE
> >
> > fabrizio=# SELECT relname, reloptions FROM pg_class WHERE relname ~
'^foo';
> >    relname   | reloptions
> > -------------+------------
> >  foo         |
> >  foo_bar_seq |
> >  foo_pkey    |
> > (3 rows)
> >
> > fabrizio=# ALTER TABLE foo RESET (noname);
> > ALTER TABLE
> >
> > fabrizio=# ALTER INDEX foo_pkey RESET (noname);
> > ALTER INDEX
> >
> > fabrizio=# ALTER TABLE foo ALTER COLUMN bar RESET (noname);
> > ALTER TABLE
> >
> >
> > If I try to "SET" an option called "noname" obviously will raise an
> > exception:
> >
> > fabrizio=# ALTER TABLE foo SET (noname=1);
> > ERROR:  unrecognized parameter "noname"
>
> Well, it's fairly harmless, but it might not be a bad idea to tighten
that up.
>

The attached patch tighten that up.

Grettings,

--
Fabrízio de Royes Mello
Consultoria/Coaching PostgreSQL
>> Timbira: http://www.timbira.com.br
>> Blog sobre TI: http://fabriziomello.blogspot.com
>> Perfil Linkedin: http://br.linkedin.com/in/fabriziomello
>> Twitter: http://twitter.com/fabriziomello
diff --git a/src/backend/access/common/reloptions.c b/src/backend/access/common/reloptions.c
index 530a1ae..4a5b767 100644
--- a/src/backend/access/common/reloptions.c
+++ b/src/backend/access/common/reloptions.c
@@ -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
@@ -382,6 +384,25 @@ initialize_reloptions(void)
 }
 
 /*
+ * 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
  *		user-defined AMs.
@@ -674,6 +695,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),
diff --git a/src/test/regress/expected/alter_table.out b/src/test/regress/expected/alter_table.out
index 0f0c638..195103e 100644
--- a/src/test/regress/expected/alter_table.out
+++ b/src/test/regress/expected/alter_table.out
@@ -7,6 +7,14 @@ COMMENT ON TABLE tmp_wrong IS 'table comment';
 ERROR:  relation "tmp_wrong" does not exist
 COMMENT ON TABLE tmp IS 'table comment';
 COMMENT ON TABLE tmp IS NULL;
+ALTER TABLE tmp SET (fillfactor=70);
+ALTER TABLE tmp RESET (fillfactor, noname);
+ERROR:  unrecognized parameter "noname"
+ALTER TABLE tmp RESET (fillfactor=70);
+ERROR:  RESET must not include values for parameters
+ALTER TABLE tmp RESET (fillfactor);
+ALTER TABLE tmp RESET (noname);
+ERROR:  unrecognized parameter "noname"
 ALTER TABLE tmp ADD COLUMN xmin integer; -- fails
 ERROR:  column name "xmin" conflicts with a system column name
 ALTER TABLE tmp ADD COLUMN a int4 default 3;
diff --git a/src/test/regress/sql/alter_table.sql b/src/test/regress/sql/alter_table.sql
index 87973c1..2cb31f2 100644
--- a/src/test/regress/sql/alter_table.sql
+++ b/src/test/regress/sql/alter_table.sql
@@ -9,6 +9,16 @@ COMMENT ON TABLE tmp_wrong IS 'table comment';
 COMMENT ON TABLE tmp IS 'table comment';
 COMMENT ON TABLE tmp IS NULL;
 
+ALTER TABLE tmp SET (fillfactor=70);
+
+ALTER TABLE tmp RESET (fillfactor, noname);
+
+ALTER TABLE tmp RESET (fillfactor=70);
+
+ALTER TABLE tmp RESET (fillfactor);
+
+ALTER TABLE tmp RESET (noname);
+
 ALTER TABLE tmp ADD COLUMN xmin integer; -- fails
 
 ALTER TABLE tmp ADD COLUMN a int4 default 3;
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to