From b7fcf68e8632e757a50352c9567bb630ed285201 Mon Sep 17 00:00:00 2001 From: Andrew Dunstan Date: Tue, 16 Nov 2010 22:18:33 -0500 Subject: [PATCH] Require VALUE keyword when extending an enum type. Based on a patch from Alvaro Herrera. --- doc/src/sgml/ref/alter_type.sgml | 8 ++-- src/backend/parser/gram.y | 16 +++---- src/test/regress/expected/enum.out | 74 +++++++++++++++--------------- src/test/regress/sql/enum.sql | 74 +++++++++++++++--------------- 4 files changed, 86 insertions(+), 86 deletions(-) diff --git a/doc/src/sgml/ref/alter_type.sgml b/doc/src/sgml/ref/alter_type.sgml index 90de2e81ef..33413450c3 100644 --- a/doc/src/sgml/ref/alter_type.sgml +++ b/doc/src/sgml/ref/alter_type.sgml @@ -28,7 +28,7 @@ ALTER TYPE name OWNER TO name RENAME ATTRIBUTE attribute_name TO new_attribute_name ALTER TYPE name RENAME TO new_name ALTER TYPE name SET SCHEMA new_schema -ALTER TYPE name ADD new_enum_value [ { BEFORE | AFTER } existing_enum_value ] +ALTER TYPE name ADD VALUE new_enum_value [ { BEFORE | AFTER } existing_enum_value ] where action is one of: @@ -106,7 +106,7 @@ ALTER TYPE name ADD - ADD [ BEFORE | AFTER ] + ADD VALUE [ BEFORE | AFTER ] This form adds a new value to an enum type. If the new value's place in @@ -238,7 +238,7 @@ ALTER TYPE name ADD Notes - ALTER TYPE ... ADD (the form that adds a new value to an + ALTER TYPE ... ADD VALUE (the form that adds a new value to an enum type) cannot be executed inside a transaction block. @@ -292,7 +292,7 @@ ALTER TYPE compfoo ADD ATTRIBUTE f3 int; To add a new value to an enum type in a particular sort position: -ALTER TYPE colors ADD 'orange' AFTER 'red'; +ALTER TYPE colors ADD VALUE 'orange' AFTER 'red'; diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 1394b21dec..d9b20746fa 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -3871,30 +3871,30 @@ enum_val_list: Sconst *****************************************************************************/ AlterEnumStmt: - ALTER TYPE_P any_name ADD_P Sconst + ALTER TYPE_P any_name ADD_P VALUE_P Sconst { AlterEnumStmt *n = makeNode(AlterEnumStmt); n->typeName = $3; - n->newVal = $5; + n->newVal = $6; n->newValNeighbor = NULL; n->newValIsAfter = true; $$ = (Node *) n; } - | ALTER TYPE_P any_name ADD_P Sconst BEFORE Sconst + | ALTER TYPE_P any_name ADD_P VALUE_P Sconst BEFORE Sconst { AlterEnumStmt *n = makeNode(AlterEnumStmt); n->typeName = $3; - n->newVal = $5; - n->newValNeighbor = $7; + n->newVal = $6; + n->newValNeighbor = $8; n->newValIsAfter = false; $$ = (Node *) n; } - | ALTER TYPE_P any_name ADD_P Sconst AFTER Sconst + | ALTER TYPE_P any_name ADD_P VALUE_P Sconst AFTER Sconst { AlterEnumStmt *n = makeNode(AlterEnumStmt); n->typeName = $3; - n->newVal = $5; - n->newValNeighbor = $7; + n->newVal = $6; + n->newValNeighbor = $8; n->newValIsAfter = true; $$ = (Node *) n; } diff --git a/src/test/regress/expected/enum.out b/src/test/regress/expected/enum.out index b1ba3f1fad..06c445ac67 100644 --- a/src/test/regress/expected/enum.out +++ b/src/test/regress/expected/enum.out @@ -39,7 +39,7 @@ ORDER BY 2; mars | 3 (3 rows) -ALTER TYPE planets ADD 'uranus'; +ALTER TYPE planets ADD VALUE 'uranus'; SELECT enumlabel, enumsortorder FROM pg_enum WHERE enumtypid = 'planets'::regtype @@ -52,10 +52,10 @@ ORDER BY 2; uranus | 4 (4 rows) -ALTER TYPE planets ADD 'mercury' BEFORE 'venus'; -ALTER TYPE planets ADD 'saturn' BEFORE 'uranus'; -ALTER TYPE planets ADD 'jupiter' AFTER 'mars'; -ALTER TYPE planets ADD 'neptune' AFTER 'uranus'; +ALTER TYPE planets ADD VALUE 'mercury' BEFORE 'venus'; +ALTER TYPE planets ADD VALUE 'saturn' BEFORE 'uranus'; +ALTER TYPE planets ADD VALUE 'jupiter' AFTER 'mars'; +ALTER TYPE planets ADD VALUE 'neptune' AFTER 'uranus'; SELECT enumlabel, enumsortorder FROM pg_enum WHERE enumtypid = 'planets'::regtype @@ -89,46 +89,46 @@ ORDER BY enumlabel::planets; (8 rows) -- errors for adding labels -ALTER TYPE planets ADD +ALTER TYPE planets ADD VALUE 'plutoplutoplutoplutoplutoplutoplutoplutoplutoplutoplutoplutoplutopluto'; ERROR: invalid enum label "plutoplutoplutoplutoplutoplutoplutoplutoplutoplutoplutoplutoplutopluto" DETAIL: Labels must be 63 characters or less. -ALTER TYPE planets ADD 'pluto' AFTER 'zeus'; +ALTER TYPE planets ADD VALUE 'pluto' AFTER 'zeus'; ERROR: "zeus" is not an existing enum label -- -- Test inserting so many values that we have to renumber -- create type insenum as enum ('L1', 'L2'); -alter type insenum add 'i1' before 'L2'; -alter type insenum add 'i2' before 'L2'; -alter type insenum add 'i3' before 'L2'; -alter type insenum add 'i4' before 'L2'; -alter type insenum add 'i5' before 'L2'; -alter type insenum add 'i6' before 'L2'; -alter type insenum add 'i7' before 'L2'; -alter type insenum add 'i8' before 'L2'; -alter type insenum add 'i9' before 'L2'; -alter type insenum add 'i10' before 'L2'; -alter type insenum add 'i11' before 'L2'; -alter type insenum add 'i12' before 'L2'; -alter type insenum add 'i13' before 'L2'; -alter type insenum add 'i14' before 'L2'; -alter type insenum add 'i15' before 'L2'; -alter type insenum add 'i16' before 'L2'; -alter type insenum add 'i17' before 'L2'; -alter type insenum add 'i18' before 'L2'; -alter type insenum add 'i19' before 'L2'; -alter type insenum add 'i20' before 'L2'; -alter type insenum add 'i21' before 'L2'; -alter type insenum add 'i22' before 'L2'; -alter type insenum add 'i23' before 'L2'; -alter type insenum add 'i24' before 'L2'; -alter type insenum add 'i25' before 'L2'; -alter type insenum add 'i26' before 'L2'; -alter type insenum add 'i27' before 'L2'; -alter type insenum add 'i28' before 'L2'; -alter type insenum add 'i29' before 'L2'; -alter type insenum add 'i30' before 'L2'; +alter type insenum add value 'i1' before 'L2'; +alter type insenum add value 'i2' before 'L2'; +alter type insenum add value 'i3' before 'L2'; +alter type insenum add value 'i4' before 'L2'; +alter type insenum add value 'i5' before 'L2'; +alter type insenum add value 'i6' before 'L2'; +alter type insenum add value 'i7' before 'L2'; +alter type insenum add value 'i8' before 'L2'; +alter type insenum add value 'i9' before 'L2'; +alter type insenum add value 'i10' before 'L2'; +alter type insenum add value 'i11' before 'L2'; +alter type insenum add value 'i12' before 'L2'; +alter type insenum add value 'i13' before 'L2'; +alter type insenum add value 'i14' before 'L2'; +alter type insenum add value 'i15' before 'L2'; +alter type insenum add value 'i16' before 'L2'; +alter type insenum add value 'i17' before 'L2'; +alter type insenum add value 'i18' before 'L2'; +alter type insenum add value 'i19' before 'L2'; +alter type insenum add value 'i20' before 'L2'; +alter type insenum add value 'i21' before 'L2'; +alter type insenum add value 'i22' before 'L2'; +alter type insenum add value 'i23' before 'L2'; +alter type insenum add value 'i24' before 'L2'; +alter type insenum add value 'i25' before 'L2'; +alter type insenum add value 'i26' before 'L2'; +alter type insenum add value 'i27' before 'L2'; +alter type insenum add value 'i28' before 'L2'; +alter type insenum add value 'i29' before 'L2'; +alter type insenum add value 'i30' before 'L2'; -- The exact values of enumsortorder will now depend on the local properties -- of float4, but in any reasonable implementation we should get at least -- 20 splits before having to renumber; so only hide values > 20. diff --git a/src/test/regress/sql/enum.sql b/src/test/regress/sql/enum.sql index 70bf8c5f1b..7ca6248309 100644 --- a/src/test/regress/sql/enum.sql +++ b/src/test/regress/sql/enum.sql @@ -26,17 +26,17 @@ FROM pg_enum WHERE enumtypid = 'planets'::regtype ORDER BY 2; -ALTER TYPE planets ADD 'uranus'; +ALTER TYPE planets ADD VALUE 'uranus'; SELECT enumlabel, enumsortorder FROM pg_enum WHERE enumtypid = 'planets'::regtype ORDER BY 2; -ALTER TYPE planets ADD 'mercury' BEFORE 'venus'; -ALTER TYPE planets ADD 'saturn' BEFORE 'uranus'; -ALTER TYPE planets ADD 'jupiter' AFTER 'mars'; -ALTER TYPE planets ADD 'neptune' AFTER 'uranus'; +ALTER TYPE planets ADD VALUE 'mercury' BEFORE 'venus'; +ALTER TYPE planets ADD VALUE 'saturn' BEFORE 'uranus'; +ALTER TYPE planets ADD VALUE 'jupiter' AFTER 'mars'; +ALTER TYPE planets ADD VALUE 'neptune' AFTER 'uranus'; SELECT enumlabel, enumsortorder FROM pg_enum @@ -49,10 +49,10 @@ WHERE enumtypid = 'planets'::regtype ORDER BY enumlabel::planets; -- errors for adding labels -ALTER TYPE planets ADD +ALTER TYPE planets ADD VALUE 'plutoplutoplutoplutoplutoplutoplutoplutoplutoplutoplutoplutoplutopluto'; -ALTER TYPE planets ADD 'pluto' AFTER 'zeus'; +ALTER TYPE planets ADD VALUE 'pluto' AFTER 'zeus'; -- -- Test inserting so many values that we have to renumber @@ -60,36 +60,36 @@ ALTER TYPE planets ADD 'pluto' AFTER 'zeus'; create type insenum as enum ('L1', 'L2'); -alter type insenum add 'i1' before 'L2'; -alter type insenum add 'i2' before 'L2'; -alter type insenum add 'i3' before 'L2'; -alter type insenum add 'i4' before 'L2'; -alter type insenum add 'i5' before 'L2'; -alter type insenum add 'i6' before 'L2'; -alter type insenum add 'i7' before 'L2'; -alter type insenum add 'i8' before 'L2'; -alter type insenum add 'i9' before 'L2'; -alter type insenum add 'i10' before 'L2'; -alter type insenum add 'i11' before 'L2'; -alter type insenum add 'i12' before 'L2'; -alter type insenum add 'i13' before 'L2'; -alter type insenum add 'i14' before 'L2'; -alter type insenum add 'i15' before 'L2'; -alter type insenum add 'i16' before 'L2'; -alter type insenum add 'i17' before 'L2'; -alter type insenum add 'i18' before 'L2'; -alter type insenum add 'i19' before 'L2'; -alter type insenum add 'i20' before 'L2'; -alter type insenum add 'i21' before 'L2'; -alter type insenum add 'i22' before 'L2'; -alter type insenum add 'i23' before 'L2'; -alter type insenum add 'i24' before 'L2'; -alter type insenum add 'i25' before 'L2'; -alter type insenum add 'i26' before 'L2'; -alter type insenum add 'i27' before 'L2'; -alter type insenum add 'i28' before 'L2'; -alter type insenum add 'i29' before 'L2'; -alter type insenum add 'i30' before 'L2'; +alter type insenum add value 'i1' before 'L2'; +alter type insenum add value 'i2' before 'L2'; +alter type insenum add value 'i3' before 'L2'; +alter type insenum add value 'i4' before 'L2'; +alter type insenum add value 'i5' before 'L2'; +alter type insenum add value 'i6' before 'L2'; +alter type insenum add value 'i7' before 'L2'; +alter type insenum add value 'i8' before 'L2'; +alter type insenum add value 'i9' before 'L2'; +alter type insenum add value 'i10' before 'L2'; +alter type insenum add value 'i11' before 'L2'; +alter type insenum add value 'i12' before 'L2'; +alter type insenum add value 'i13' before 'L2'; +alter type insenum add value 'i14' before 'L2'; +alter type insenum add value 'i15' before 'L2'; +alter type insenum add value 'i16' before 'L2'; +alter type insenum add value 'i17' before 'L2'; +alter type insenum add value 'i18' before 'L2'; +alter type insenum add value 'i19' before 'L2'; +alter type insenum add value 'i20' before 'L2'; +alter type insenum add value 'i21' before 'L2'; +alter type insenum add value 'i22' before 'L2'; +alter type insenum add value 'i23' before 'L2'; +alter type insenum add value 'i24' before 'L2'; +alter type insenum add value 'i25' before 'L2'; +alter type insenum add value 'i26' before 'L2'; +alter type insenum add value 'i27' before 'L2'; +alter type insenum add value 'i28' before 'L2'; +alter type insenum add value 'i29' before 'L2'; +alter type insenum add value 'i30' before 'L2'; -- The exact values of enumsortorder will now depend on the local properties -- of float4, but in any reasonable implementation we should get at least -- 2.40.0