Commit b7fcf68e authored by Andrew Dunstan's avatar Andrew Dunstan

Require VALUE keyword when extending an enum type. Based on a patch from Alvaro Herrera.

parent 4acf99b2
......@@ -28,7 +28,7 @@ ALTER TYPE <replaceable class="PARAMETER">name</replaceable> OWNER TO <replaceab
ALTER TYPE <replaceable class="PARAMETER">name</replaceable> RENAME ATTRIBUTE <replaceable class="PARAMETER">attribute_name</replaceable> TO <replaceable class="PARAMETER">new_attribute_name</replaceable>
ALTER TYPE <replaceable class="PARAMETER">name</replaceable> RENAME TO <replaceable class="PARAMETER">new_name</replaceable>
ALTER TYPE <replaceable class="PARAMETER">name</replaceable> SET SCHEMA <replaceable class="PARAMETER">new_schema</replaceable>
ALTER TYPE <replaceable class="PARAMETER">name</replaceable> ADD <replaceable class="PARAMETER">new_enum_value</replaceable> [ { BEFORE | AFTER } <replaceable class="PARAMETER">existing_enum_value</replaceable> ]
ALTER TYPE <replaceable class="PARAMETER">name</replaceable> ADD VALUE <replaceable class="PARAMETER">new_enum_value</replaceable> [ { BEFORE | AFTER } <replaceable class="PARAMETER">existing_enum_value</replaceable> ]
<phrase>where <replaceable class="PARAMETER">action</replaceable> is one of:</phrase>
......@@ -106,7 +106,7 @@ ALTER TYPE <replaceable class="PARAMETER">name</replaceable> ADD <replaceable cl
</varlistentry>
<varlistentry>
<term><literal>ADD [ BEFORE | AFTER ]</literal></term>
<term><literal>ADD VALUE [ BEFORE | AFTER ]</literal></term>
<listitem>
<para>
This form adds a new value to an enum type. If the new value's place in
......@@ -238,7 +238,7 @@ ALTER TYPE <replaceable class="PARAMETER">name</replaceable> ADD <replaceable cl
<title>Notes</title>
<para>
<command>ALTER TYPE ... ADD</> (the form that adds a new value to an
<command>ALTER TYPE ... ADD VALUE</> (the form that adds a new value to an
enum type) cannot be executed inside a transaction block.
</para>
......@@ -292,7 +292,7 @@ ALTER TYPE compfoo ADD ATTRIBUTE f3 int;
<para>
To add a new value to an enum type in a particular sort position:
<programlisting>
ALTER TYPE colors ADD 'orange' AFTER 'red';
ALTER TYPE colors ADD VALUE 'orange' AFTER 'red';
</programlisting>
</para>
</refsect1>
......
......@@ -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;
}
......
......@@ -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.
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment