test ALTER TYPE.. RENAME VALUE
authorAmruta Deolasee <[email protected]>
Mon, 10 Sep 2018 06:44:12 +0000 (06:44 +0000)
committerPavan Deolasee <[email protected]>
Tue, 11 Sep 2018 09:48:05 +0000 (15:18 +0530)
src/test/regress/expected/xl_misc.out
src/test/regress/sql/xl_misc.sql

index bc435893aca7eb49b9396abd180478f88a483119..54ceb9a87535a843df0912f580a589eb14c8bc88 100644 (file)
@@ -366,3 +366,65 @@ SELECT * FROM t1_tmp ORDER BY empno;
  develop   |    11 |   5200 | 25100
 (10 rows)
 
+CREATE TYPE rainbow AS ENUM ('red', 'orange', 'yellow', 'green', 'blue', 'purple');
+CREATE TABLE enumtest_parent (id rainbow PRIMARY KEY);
+CREATE TABLE enumtest_child (parent rainbow REFERENCES enumtest_parent);
+INSERT INTO enumtest_parent VALUES ('red');
+INSERT INTO enumtest_child VALUES ('red');
+SELECT id FROM enumtest_parent;
+ id  
+-----
+ red
+(1 row)
+
+SELECT * FROM enumtest_child;
+ parent 
+--------
+ red
+(1 row)
+
+               
+-- check renaming a value
+ALTER TYPE rainbow RENAME VALUE 'red' TO 'crimson';
+-- check that renaming a non-existent value fails
+ALTER TYPE rainbow RENAME VALUE 'red' TO 'white';
+ERROR:  "red" is not an existing enum label
+-- check that renaming to an existent value fails
+ALTER TYPE rainbow RENAME VALUE 'blue' TO 'green';
+ERROR:  enum label "green" already exists
+-- check that RENAMED value is refected in tables
+SELECT id FROM enumtest_parent;
+   id    
+---------
+ crimson
+(1 row)
+
+SELECT id FROM enumtest_child;
+ERROR:  column "id" does not exist
+LINE 1: SELECT id FROM enumtest_child;
+               ^
+-- Try inserting old and new values
+INSERT INTO enumtest_parent VALUES ('green');
+INSERT INTO enumtest_child VALUES ('crimson');
+-- try inserting non existing value after renaming
+INSERT INTO enumtest_parent VALUES ('red');
+ERROR:  invalid input value for enum rainbow: "red"
+LINE 1: INSERT INTO enumtest_parent VALUES ('red');
+                                            ^
+SELECT id FROM enumtest_parent;
+   id    
+---------
+ crimson
+ green
+(2 rows)
+
+SELECT * FROM enumtest_child;
+ parent  
+---------
+ crimson
+ crimson
+(2 rows)
+
+DROP TABLE enumtest_child;
+DROP TABLE enumtest_parent;
+DROP TYPE rainbow;
index 9201486c8abe213083d9c52d0bc05c962eef8755..62faf3a0ee5e0954b2d792f2e62ea199f47e44f6 100644 (file)
@@ -210,3 +210,33 @@ INSERT INTO empsalary VALUES
 CREATE TEMPORARY TABLE t1_tmp (depname text, empno int, salary int, sum int);
 INSERT INTO t1_tmp SELECT depname, empno, salary, sum(salary) OVER (PARTITION BY depname) FROM empsalary;
 SELECT * FROM t1_tmp ORDER BY empno;
+
+CREATE TYPE rainbow AS ENUM ('red', 'orange', 'yellow', 'green', 'blue', 'purple');
+CREATE TABLE enumtest_parent (id rainbow PRIMARY KEY);
+CREATE TABLE enumtest_child (parent rainbow REFERENCES enumtest_parent);
+INSERT INTO enumtest_parent VALUES ('red');
+INSERT INTO enumtest_child VALUES ('red');
+SELECT id FROM enumtest_parent;
+SELECT * FROM enumtest_child;
+               
+-- check renaming a value
+ALTER TYPE rainbow RENAME VALUE 'red' TO 'crimson';
+-- check that renaming a non-existent value fails
+ALTER TYPE rainbow RENAME VALUE 'red' TO 'white';
+-- check that renaming to an existent value fails
+ALTER TYPE rainbow RENAME VALUE 'blue' TO 'green';
+-- check that RENAMED value is refected in tables
+SELECT id FROM enumtest_parent;
+SELECT id FROM enumtest_child;
+
+-- Try inserting old and new values
+INSERT INTO enumtest_parent VALUES ('green');
+INSERT INTO enumtest_child VALUES ('crimson');
+-- try inserting non existing value after renaming
+INSERT INTO enumtest_parent VALUES ('red');
+SELECT id FROM enumtest_parent;
+SELECT * FROM enumtest_child;
+
+DROP TABLE enumtest_child;
+DROP TABLE enumtest_parent;
+DROP TYPE rainbow;