mirror of
https://github.com/postgres/postgres.git
synced 2025-09-09 13:09:39 +03:00
Allow IF NOT EXISTS when add a new enum label.
If the label is already in the enum the statement becomes a no-op. This will reduce the pain that comes from our not allowing this operation inside a transaction block. Andrew Dunstan, reviewed by Tom Lane and Magnus Hagander.
This commit is contained in:
@@ -54,6 +54,26 @@ ALTER TYPE planets ADD VALUE
|
||||
|
||||
ALTER TYPE planets ADD VALUE 'pluto' AFTER 'zeus';
|
||||
|
||||
-- if not exists tests
|
||||
|
||||
-- existing value gives error
|
||||
|
||||
-- We can't do this test because the error contains the
|
||||
-- offending Oid value, which is unpredictable.
|
||||
-- ALTER TYPE planets ADD VALUE 'mercury';
|
||||
|
||||
-- unless IF NOT EXISTS is specified
|
||||
ALTER TYPE planets ADD VALUE IF NOT EXISTS 'mercury';
|
||||
|
||||
-- should be neptune, not mercury
|
||||
SELECT enum_last(NULL::planets);
|
||||
|
||||
ALTER TYPE planets ADD VALUE IF NOT EXISTS 'pluto';
|
||||
|
||||
-- should be pluto, i.e. the new value
|
||||
SELECT enum_last(NULL::planets);
|
||||
|
||||
|
||||
--
|
||||
-- Test inserting so many values that we have to renumber
|
||||
--
|
||||
|
Reference in New Issue
Block a user