|
|
dkLab | Constructor | PostgreSQL 8.3 ALTER ENUM emulation: element addition/removal is possible
2008-08-13
Download ENUM "on the fly" altering functions for PostgreSQL 8.3:
How to installIt's simple: just download, unpack and execute as usual SQL script. The new schema "enum" will be created in you database; it contains all needed functions. The problemIt is well-known that ALTER TYPE construction for handy PostgreSQL 8.3 ENUM datatype does not exist (at least in 8.3.3). So, you could say
Usage samples: enum_add() and enum_del()Proposed solution consists of two functions which allow to add or remove ENUM elements with all needed constraints checks. Here are usage samples. -- Create a ENUM type and a referring table.
CREATE TYPE my_enum AS ENUM('first', 'second');
CREATE TABLE my_table(id INTEGER, my my_enum);
-- Insert test data to the table.
INSERT INTO my_table(id, my) VALUES(1, 'second');
-- Add a new element to the ENUM "on the fly".
SELECT enum.enum_add('my_enum', 'third');
-- Remove an element from the ENUM "on the fly".
SELECT enum.enum_del('my_enum', 'first');
You see, we could remove elements from -- Remove an element from the ENUM "on the fly".
SELECT enum.enum_del('my_enum', 'first');
! ERROR: Cannot delete the ENUM element my_enum.second: column public.my_table.my contains references
So, the database integrity is not broken while a ENUM element is deleted.
Битопливные котлы с раздельными камерами сгорания Kiturami KRM. | Автобусы паз . Российские автобусы на Грузовик.ру | если вы ищете для каско онлайн калькулятор на нашем сайте | www.x-point.ru - купить ноутбук |