I have a table column that uses an enum
type. I wish to update that enum
type to have an additional possible value. I don't want to delete any existing values, just add the new value. What is the simplest way to do this?

- 7,115
- 4
- 45
- 59

- 24,116
- 22
- 58
- 96
19 Answers
PostgreSQL 9.1 introduces ability to ALTER Enum types:
ALTER TYPE enum_type ADD VALUE 'new_value'; -- appends to list
ALTER TYPE enum_type ADD VALUE 'new_value' BEFORE 'old_value';
ALTER TYPE enum_type ADD VALUE 'new_value' AFTER 'old_value';

- 10,848
- 6
- 41
- 42

- 15,573
- 9
- 52
- 68
-
3what is the "enum_type"? field name, table_field name? or something else? how should i hit that? I have table "grades" and i have column "type" And in db dump i get this: CONSTRAINT grades_type_check CHECK (((type)::text = ANY ((ARRAY['exam'::character varying, 'test'::character varying, 'extra'::character varying, 'midterm'::character varying, 'final'::character varying])::text[]))) – Dec 19 '14 at 09:23
-
2enum_type is just a your own enum type name @mariotanenbaum. If you your enum is a "type" then this is what you should use. – Dariusz Dec 19 '14 at 15:13
-
hm, i don't get it. I think i was quite clear. I have column in a table called "type" actually it's registered as a varchar. And for that very same column i have constraint which defines it to be one of values in an array. So it's an enum. I tried all variations that came to my mind but nothing worked. I don't know what to do now... – Dec 19 '14 at 16:24
-
@mariotanenbaum PostgreSQL has native support for real enum types, such that it manages the constraints and the ordering for you. – Pointy Jan 23 '15 at 14:37
-
yes, but laravel's migration don't use that.. they make it with constraints – Jan 24 '15 at 14:32
-
64is it possible to remove one ? – Ced May 23 '17 at 00:23
-
10Adding to @DrewNoakes' comment, if you are using db-migrate (which runs in transaction), then you might get an error: ERROR: ALTER TYPE ... ADD cannot run inside a transaction block The solution is mentioned here (by Hubbitus): https://stackoverflow.com/a/41696273/1161370 – Mahesh Oct 26 '17 at 19:24
-
1@Ced not without dropping and recreating the enum type. Notes section in https://www.postgresql.org/docs/9.1/sql-altertype.html describes the details. – Zmey Feb 10 '20 at 09:41
-
This should be the accepted answer for all but ancient PostgreSQL versions @ian – deyhle Feb 26 '20 at 08:10
-
3you can't remove it so it makes dow migration impossible so have to resort to other methods – Muhammad Umer May 11 '20 at 20:30
NOTE if you're using PostgreSQL 9.1 or later, and you are ok with making changes outside of a transaction, see this answer for a simpler approach.
I had the same problem few days ago and found this post. So my answer can be helpful for someone who is looking for solution :)
If you have only one or two columns which use the enum type you want to change, you can try this. Also you can change the order of values in the new type.
-- 1. rename the enum type you want to change
alter type some_enum_type rename to _some_enum_type;
-- 2. create new type
create type some_enum_type as enum ('old', 'values', 'and', 'new', 'ones');
-- 3. rename column(s) which uses our enum type
alter table some_table rename column some_column to _some_column;
-- 4. add new column of new type
alter table some_table add some_column some_enum_type not null default 'new';
-- 5. copy values to the new column
update some_table set some_column = _some_column::text::some_enum_type;
-- 6. remove old column and type
alter table some_table drop column _some_column;
drop type _some_enum_type;
3-6 should be repeated if there is more than 1 column.
-
13It's worth mentioning that this can all be done in a single transaction, so it's mostly safe to do it in a production database. – David Leppik Jul 08 '11 at 20:41
-
73This was never a good idea. Since 9.1 you can do it all with [`ALTER TYPE`](http://www.postgresql.org/docs/9.1/static/sql-altertype.html). But even before that, `ALTER TABLE foo ALTER COLUMN bar TYPE new_type USING bar::text::new_type;` was far superior. – Erwin Brandstetter Nov 18 '11 at 22:46
-
1Be aware that older versions of Postgres don't support renaming types. Specifically the version of Postgres on Heroku (shared db, I believe they use PG 8.3) doesn't support it. – Ortwin Gentz Nov 30 '11 at 09:54
-
16You can collapse steps 3, 4, 5 and 6 together into a single statement: `ALTER TABLE some_table ALTER COLUMN some_column TYPE some_enum_type USING some_column::text::some_enum_type;` – glyphobet Aug 07 '13 at 20:57
-
1From what the docs say, there are 2 problems with ```ALTER TYPE```: 1) you can't do it inside a transaction if you do an ```ADD VALUE```, and 2) performance can suffer with newer values in the enum (both according to http://www.postgresql.org/docs/9.1/static/sql-altertype.html) – Asfand Qazi Dec 03 '13 at 09:38
-
4If doing this on a live table, lock the table during the procedure. The default transaction isolation level in postgresql will not prevent new rows being inserted by other transactions during this transaction, so you may be left with wrongly populated rows. – Sérgio Carvalho Mar 12 '14 at 16:47
-
1@ErwinBrandstetter - I want to extend a type in a transaction on a column with a default and that is referenced in several views. Using this answer's code works fine. Using your simpler `ALTER COLUMN` suggestion, I get `ERROR: cannot alter type of a column used by a view or rule`. I even tried defining an implicit cast, but no luck. In my case, am I best following this answer, or is there still a "far superior" way? I suppose I could manually drop and recreate all the views. If that's better, do you care to elaborate on what specifically makes this answer a poor choice? Thanks! – gilly3 Aug 17 '19 at 01:03
-
@gilly3: The solution here would not help at all with depending views or rules. Either way, this goes beyond the scope of a comment. Please ask your question as *question*, providing details of your case. You can always reference posts here for context and drop a comment to link back. – Erwin Brandstetter Aug 17 '19 at 01:17
A possible solution is the following; precondition is, that there are not conflicts in the used enum values. (e.g. when removing an enum value, be sure that this value is not used anymore.)
-- rename the old enum
alter type my_enum rename to my_enum__;
-- create the new enum
create type my_enum as enum ('value1', 'value2', 'value3');
-- alter all you enum columns
alter table my_table
alter column my_column type my_enum using my_column::text::my_enum;
-- drop the old enum
drop type my_enum__;
Also in this way the column order will not be changed.
-
2+1 this is the way to go pre-9.1 and still the way to go for deleting or modifying elements. – Feb 12 '13 at 13:41
-
This is by far the best answer for my solution, which adds new enums to an existing enum type, where we are keeping all the old enums and adding new ones. Additionally our update script is transactional. Great post! – Darin Peterson Jul 16 '13 at 20:38
-
1Brilliant answer! Avoids hacks around `pg_enum` that can actually break things and is transactional, unlike `ALTER TYPE ... ADD`. – NathanAldenSr Nov 16 '15 at 18:52
-
10In case your column has a default value you will receive the following error: `default for column "my_column" cannot be cast automatically to type "my_enum"`. You will have to do the following: `ALTER TABLE "my_table" ALTER COLUMN "my_column" DROP DEFAULT, ALTER COLUMN "my_column" TYPE "my_type" USING ("my_column"::text::"my_type"), ALTER COLUMN "my_column" SET DEFAULT 'my_default_value';` – n1ru4l Mar 15 '19 at 08:15
If you are using Postgres 12 (or later) you can just run ALTER TYPE ... ADD VALUE
inside of transaction (documentation).
If ALTER TYPE ... ADD VALUE (the form that adds a new value to an enum type) is executed inside a transaction block, the new value cannot be used until after the transaction has been committed.
So no hacks needed in migrations.
UPD: here is an example (thanks to Nick for it)
ALTER TYPE enum_type ADD VALUE 'new_value';

- 2,011
- 16
- 26
-
2
-
2
-
2The one further problem is that you cannot then use that new value within the same transaction (as mentioned in the documentation linked in the answer). If using Flyway you can simply create a second conversion file for the same release since the second file will start a fresh transaction. – RedYeti Oct 07 '22 at 08:23
If you fall into situation when you should add enum
values in transaction, f.e. execute it in flyway migration on ALTER TYPE
statement you will be get error ERROR: ALTER TYPE ... ADD cannot run inside a transaction block
(see flyway issue #350) you could add such values into pg_enum
directly as workaround (type_egais_units
is name of target enum
):
INSERT INTO pg_enum (enumtypid, enumlabel, enumsortorder)
SELECT 'type_egais_units'::regtype::oid, 'NEW_ENUM_VALUE', ( SELECT MAX(enumsortorder) + 1 FROM pg_enum WHERE enumtypid = 'type_egais_units'::regtype )

- 5,161
- 3
- 41
- 47
-
11However, this will require granting admin permissions, because it's changes system table. – asnelzin Jan 23 '18 at 08:59
-
Or you could add the new values in separate flyway migration scripts – Robson Oliveira Sep 18 '20 at 12:25
-
Flyway manages transactions for their migrations. About what separate scripts are you speak? – Hubbitus Sep 18 '20 at 13:01
Complementing @Dariusz 1
For Rails 4.2.1, there's this doc section:
== Transactional Migrations
If the database adapter supports DDL transactions, all migrations will automatically be wrapped in a transaction. There are queries that you can't execute inside a transaction though, and for these situations you can turn the automatic transactions off.
class ChangeEnum < ActiveRecord::Migration
disable_ddl_transaction!
def up
execute "ALTER TYPE model_size ADD VALUE 'new_value'"
end
end

- 1
- 1

- 612
- 6
- 15
-
3this! if you are playing with enums in modern rails, this is exactly what you are looking for. – Eli Albért Aug 15 '17 at 22:26
-
1
just in case, if you are using Rails and you have several statements you will need to execute one by one, like:
execute "ALTER TYPE XXX ADD VALUE IF NOT EXISTS 'YYY';"
execute "ALTER TYPE XXX ADD VALUE IF NOT EXISTS 'ZZZ';"

- 1,203
- 13
- 19
-
2The `IF NOT EXISTS` bit was invaluable in what I was working on. Thanks for that. – Patrick Sep 20 '21 at 15:37
From Postgres 9.1 Documentation:
ALTER TYPE name ADD VALUE new_enum_value [ { BEFORE | AFTER } existing_enum_value ]
Example:
ALTER TYPE user_status ADD VALUE 'PROVISIONAL' AFTER 'NORMAL'

- 1,976
- 25
- 30
-
3Also from the documentation: Comparisons involving an added enum value will sometimes be slower than comparisons involving only original members of the enum type. [.... detailed snipped as too long for stackoverflow comment...] The slowdown is usually insignificant; but if it matters, optimal performance can be regained by dropping and recreating the enum type, or by dumping and reloading the database. – Aaron Zinman May 27 '13 at 20:43
Disclaimer: I haven't tried this solution, so it might not work ;-)
You should be looking at pg_enum
. If you only want to change the label of an existing ENUM, a simple UPDATE will do it.
To add a new ENUM values:
- First insert the new value into
pg_enum
. If the new value has to be the last, you're done. - If not (you need to a new ENUM value in between existing ones), you'll have to update each distinct value in your table, going from the uppermost to the lowest...
- Then you'll just have to rename them in
pg_enum
in the opposite order.
Illustration
You have the following set of labels:
ENUM ('enum1', 'enum2', 'enum3')
and you want to obtain:
ENUM ('enum1', 'enum1b', 'enum2', 'enum3')
then:
INSERT INTO pg_enum (OID, 'newenum3');
UPDATE TABLE SET enumvalue TO 'newenum3' WHERE enumvalue='enum3';
UPDATE TABLE SET enumvalue TO 'enum3' WHERE enumvalue='enum2';
then:
UPDATE TABLE pg_enum SET name='enum1b' WHERE name='enum2' AND enumtypid=OID;
And so on...
-
1["In general you should try hard to avoid manually mangling the catalogs ... hacking the system tables like this."](http://www.depesz.com/2010/10/27/waiting-for-9-1-adding-values-to-enums/) says Andrew Dunstan and I'm inclined to think he's right. – Apr 30 '12 at 08:41
I can't seem to post a comment, so I'll just say that updating pg_enum works in Postgres 8.4 . For the way our enums are set up, I've added new values to existing enum types via:
INSERT INTO pg_enum (enumtypid, enumlabel)
SELECT typelem, 'NEWENUM' FROM pg_type WHERE
typname = '_ENUMNAME_WITH_LEADING_UNDERSCORE';
It's a little scary, but it makes sense given the way Postgres actually stores its data.

- 727
- 5
- 15
-
1Great answer! Helps just for appending on a new enum, but obviously doesn't solve the case on where you have to re-order. – Mahmoud Abdelkader Feb 17 '11 at 05:12
-
3["In general you should try hard to avoid manually mangling the catalogs ... hacking the system tables like this."](http://www.depesz.com/2010/10/27/waiting-for-9-1-adding-values-to-enums/) says Andrew Dunstan and I'm inclined to think he's right. – Apr 30 '12 at 08:41
-
Along with leading underscore for typename, they are also case sensitive. I almost lost my mind trying to select by typename from pg_type table. – Mahesh Jul 31 '19 at 00:24
Updating pg_enum works, as does the intermediary column trick highlighted above. One can also use USING magic to change the column's type directly:
CREATE TYPE test AS enum('a', 'b');
CREATE TABLE foo (bar test);
INSERT INTO foo VALUES ('a'), ('b');
ALTER TABLE foo ALTER COLUMN bar TYPE varchar;
DROP TYPE test;
CREATE TYPE test as enum('a', 'b', 'c');
ALTER TABLE foo ALTER COLUMN bar TYPE test
USING CASE
WHEN bar = ANY (enum_range(null::test)::varchar[])
THEN bar::test
WHEN bar = ANY ('{convert, these, values}'::varchar[])
THEN 'c'::test
ELSE NULL
END;
As long as you've no functions that explicitly require or return that enum, you're good. (pgsql will complain when you drop the type if there are.)
Also, note that PG9.1 is introducing an ALTER TYPE statement, which will work on enums:
http://developer.postgresql.org/pgdocs/postgres/release-9-1-alpha.html

- 605,456
- 145
- 1,078
- 1,228

- 75,850
- 13
- 131
- 154
-
The relevant documentation for PostgreSQL 9.1 can now be found at http://www.postgresql.org/docs/9.1/static/sql-altertype.html – Wichert Akkerman Oct 12 '11 at 14:09
-
1`ALTER TABLE foo ALTER COLUMN bar TYPE test USING bar::text::new_type;` But largely irrelevant now ... – Erwin Brandstetter Nov 18 '11 at 22:51
-
Similarly to what Erwin said, `... USING bar::type` worked for me. I didn't even have to specify `::text`. – Daniel Werner Mar 21 '13 at 10:05
Can't add a comment to the appropriate place, but ALTER TABLE foo ALTER COLUMN bar TYPE new_enum_type USING bar::text::new_enum_type
with a default on the column failed. I had to:
ALTER table ALTER COLUMN bar DROP DEFAULT
;
and then it worked.

- 3,056
- 1
- 21
- 32

- 81
- 1
- 5
Here is a more general but a rather fast-working solution, which apart from changing the type itself updates all columns in the database using it. The method can be applied even if a new version of ENUM is different by more than one label or misses some of the original ones. The code below replaces my_schema.my_type AS ENUM ('a', 'b', 'c')
with ENUM ('a', 'b', 'd', 'e')
:
CREATE OR REPLACE FUNCTION tmp() RETURNS BOOLEAN AS
$BODY$
DECLARE
item RECORD;
BEGIN
-- 1. create new type in replacement to my_type
CREATE TYPE my_schema.my_type_NEW
AS ENUM ('a', 'b', 'd', 'e');
-- 2. select all columns in the db that have type my_type
FOR item IN
SELECT table_schema, table_name, column_name, udt_schema, udt_name
FROM information_schema.columns
WHERE
udt_schema = 'my_schema'
AND udt_name = 'my_type'
LOOP
-- 3. Change the type of every column using my_type to my_type_NEW
EXECUTE
' ALTER TABLE ' || item.table_schema || '.' || item.table_name
|| ' ALTER COLUMN ' || item.column_name
|| ' TYPE my_schema.my_type_NEW'
|| ' USING ' || item.column_name || '::text::my_schema.my_type_NEW;';
END LOOP;
-- 4. Delete an old version of the type
DROP TYPE my_schema.my_type;
-- 5. Remove _NEW suffix from the new type
ALTER TYPE my_schema.my_type_NEW
RENAME TO my_type;
RETURN true;
END
$BODY$
LANGUAGE 'plpgsql';
SELECT * FROM tmp();
DROP FUNCTION tmp();
The whole process will run fairly quickly, because if the order of labels persists, no actual change of data will happen. I applied the method on 5 tables using my_type
and having 50,000−70,000 rows in each, and the whole process took just 10 seconds.
Of course, the function will return an exception in case if labels that are missing in the new version of the ENUM are used somewhere in the data, but in such situation something should be done beforehand anyway.

- 842
- 15
- 29
-
This is really valuable. The problem is with views using the old ENUM, though. They must be dropped and recreated, which is far more complicated considering other views depending on the dropped ones. Not speaking about composite types... – Ondřej Bouda Sep 12 '14 at 17:12
For those looking for an in-transaction solution, the following seems to work.
Instead of an ENUM
, a DOMAIN
shall be used on type TEXT
with a constraint checking that the value is within the specified list of allowed values (as suggested by some comments). The only problem is that no constraint can be added (and thus neither modified) to a domain if it is used by any composite type (the docs merely says this "should eventually be improved"). Such a restriction may be worked around, however, using a constraint calling a function, as follows.
START TRANSACTION;
CREATE FUNCTION test_is_allowed_label(lbl TEXT) RETURNS BOOL AS $function$
SELECT lbl IN ('one', 'two', 'three');
$function$ LANGUAGE SQL IMMUTABLE;
CREATE DOMAIN test_domain AS TEXT CONSTRAINT val_check CHECK (test_is_allowed_label(value));
CREATE TYPE test_composite AS (num INT, word test_domain);
CREATE TABLE test_table (val test_composite);
INSERT INTO test_table (val) VALUES ((1, 'one')::test_composite), ((3, 'three')::test_composite);
-- INSERT INTO test_table (val) VALUES ((4, 'four')::test_composite); -- restricted by the CHECK constraint
CREATE VIEW test_view AS SELECT * FROM test_table; -- just to show that the views using the type work as expected
CREATE OR REPLACE FUNCTION test_is_allowed_label(lbl TEXT) RETURNS BOOL AS $function$
SELECT lbl IN ('one', 'two', 'three', 'four');
$function$ LANGUAGE SQL IMMUTABLE;
INSERT INTO test_table (val) VALUES ((4, 'four')::test_composite); -- allowed by the new effective definition of the constraint
SELECT * FROM test_view;
CREATE OR REPLACE FUNCTION test_is_allowed_label(lbl TEXT) RETURNS BOOL AS $function$
SELECT lbl IN ('one', 'two', 'three');
$function$ LANGUAGE SQL IMMUTABLE;
-- INSERT INTO test_table (val) VALUES ((4, 'four')::test_composite); -- restricted by the CHECK constraint, again
SELECT * FROM test_view; -- note the view lists the restricted value 'four' as no checks are made on existing data
DROP VIEW test_view;
DROP TABLE test_table;
DROP TYPE test_composite;
DROP DOMAIN test_domain;
DROP FUNCTION test_is_allowed_label(TEXT);
COMMIT;
Previously, I used a solution similar to the accepted answer, but it is far from being good once views or functions or composite types (and especially views using other views using the modified ENUMs...) are considered. The solution proposed in this answer seems to work under any conditions.
The only disadvantage is that no checks are performed on existing data when some allowed values are removed (which might be acceptable, especially for this question). (A call to ALTER DOMAIN test_domain VALIDATE CONSTRAINT val_check
ends up with the same error as adding a new constraint to the domain used by a composite type, unfortunately.)
Note that a slight modification such as (it works, actually - it was my error)CHECK (value = ANY(get_allowed_values()))
, where get_allowed_values()
function returned the list of allowed values, would not work - which is quite strange, so I hope the solution proposed above works reliably (it does for me, so far...).

- 1,061
- 11
- 16
As discussed above, ALTER
command cannot be written inside a transaction. The suggested way is to insert into the pg_enum table directly, by retrieving the typelem from pg_type table
and calculating the next enumsortorder number
;
Following is the code that I use. (Checks if duplicate value exists before inserting (constraint between enumtypid and enumlabel name)
INSERT INTO pg_enum (enumtypid, enumlabel, enumsortorder)
SELECT typelem,
'NEW_ENUM_VALUE',
(SELECT MAX(enumsortorder) + 1
FROM pg_enum e
JOIN pg_type p
ON p.typelem = e.enumtypid
WHERE p.typname = '_mytypename'
)
FROM pg_type p
WHERE p.typname = '_mytypename'
AND NOT EXISTS (
SELECT * FROM
pg_enum e
JOIN pg_type p
ON p.typelem = e.enumtypid
WHERE e.enumlabel = 'NEW_ENUM_VALUE'
AND p.typname = '_mytypename'
)
Note that your type name is prepended with an underscore in the pg_type table. Also, the typname needs to be all lowercase in the where clause.
Now this can be written safely into your db migrate script.

- 3,727
- 1
- 39
- 49
DB::statement("ALTER TABLE users DROP CONSTRAINT users_user_type_check");
$types = ['old_type1', 'old_type1', 'new_type3'];
$result = join( ', ', array_map(function ($value){
return sprintf("'%s'::character varying", $value);
}, $types));
DB::statement("ALTER TABLE users ADD CONSTRAINT users_user_type_check CHECK (user_type::text = ANY (ARRAY[$result]::text[]))");
-
This solution is working for me. users is table of database and user_type is column of users table, $types = ['old_type1', 'old_type1', 'your_new_value_of_enum']; – M Awais Adil Sep 13 '22 at 13:49
-
create a new migration and just put the above code in migration up method – M Awais Adil Sep 13 '22 at 13:53
When using Navicat you can go to types (under view -> others -> types) - get the design view of the type - and click the "add label" button.

- 188
- 1
- 14
-
1Would be nice but in real life, it's not useful: `ERROR: cannot drop type foo because other objects depend on it HINT: Use DROP ... CASCADE to drop the dependent objects too.` – Ortwin Gentz Nov 18 '11 at 22:08
-
Weird, it worked for me. (Not sure why you use DROP when TS only wanted to add a value to enum field) – jvv Nov 30 '11 at 09:13
-
1I didn't do a DROP specifically but went exactly after your procedure. I assume Navicat does the DROP behind the scenes and fails. I'm using Navicat 9.1.5 Lite. – Ortwin Gentz Nov 30 '11 at 09:52
-
I don't know if have other option but we can drop the value using:
select oid from pg_type where typname = 'fase';'
select * from pg_enum where enumtypid = 24773;'
select * from pg_enum where enumtypid = 24773 and enumsortorder = 6;
delete from pg_enum where enumtypid = 24773 and enumsortorder = 6;
Simplest: get rid of enums. They are not easily modifiable, and thus should very rarely be used.
-
2
-
If I did that, then I'd be storing the values as strings.. which is pretty bleh.. unless I stored the enumeration in my code.. but that's getting a bit messy.. – Ian Nov 22 '09 at 06:36
-
1
-
1Seems like a waste to store them that way.. when I index those fields they'll add quite a bit more load than an int or enum would.. – Ian Nov 23 '09 at 14:01
-
1
-
Well, right now it's only about 50,000 rows.. but I'm hoping to increase that significantly.. – Ian Nov 23 '09 at 20:52
-
1@depesz - would you still recommend against using enums with 9.1 nearing release? It just seems to my admittedly novice thinking, that enums are more efficient for big tables – David Powell Dec 17 '10 at 00:33
-
5@Grazer: in 9.1 you can add values to enum ( http://www.depesz.com/index.php/2010/10/27/waiting-for-9-1-adding-values-to-enums/ ) - but you still can't remove old ones. – Dec 17 '10 at 12:07
-
-
3@WillSheppard - *I* think that basically never. I think that custom types based on text with check constraints as much better in any case. – Apr 18 '12 at 09:45
-
@depesz with a `domain` you get a custom type based on text with a check constraint - that you can reuse between tables. Would you agree that is sometimes the way to go? – Apr 30 '12 at 08:30
-
3
-
@depesz: If you offered alternatives and/or explained more thoroughly why enums are not to be used, you would have probably got more upvotes - and less downvotes (and I agree, enums are evil) – ypercubeᵀᴹ Apr 30 '12 at 12:40
-
1I notice that "Allow renaming and deleting enumerated values from an existing enumerated data type" is on [the developers TODO list](http://wiki.postgresql.org/wiki/Todo). I wonder when this will land, as I guess that would finally make enums useful. – Feb 12 '13 at 10:22
-
-
I wonder if deletion would be an easier thing if it only worked on unused enum elements and just failed otherwise. That would be enough to make enums useful imo. – Feb 12 '13 at 10:42
-
-
Good question: I don't know how they work internally but I guess if there is no reference count or whatever, then it's not much easier either way. – Feb 12 '13 at 13:36
-
1There isn't. And remember that keeping reference count is, to say it lightly, not trivial, when you take into account multiple concurrent queries, and on top of it, transactions. – Feb 12 '13 at 14:39
-
1@JackDouglas Domains would be a great replacement, only if... "Currently, ALTER DOMAIN ADD CONSTRAINT [...] will fail if the named domain or any derived domain is used within a composite-type column of any table in the database." That said, it is not a complete replacement for ENUMs not being able to add new labels inside transactions as long as composite types are considered (which unfortunately are in my case). – Ondřej Bouda Sep 12 '14 at 18:04
-
@JackDouglas It seems I managed to work around this limitation - see my answer :) – Ondřej Bouda Sep 12 '14 at 20:06
-
@OndřejBouda nice. Do you know about [DBA.SE](http://dba.stackexchange.com/)? Don't be put off by the name, I think you'd like it there :) – Sep 13 '14 at 07:13
-
-