Re: [GENERAL] Modifying an existing table to use an ENUM instead of an int

2010-06-07 Thread Mike Christensen
Doh! I suck, I had a CHECK constraint on that column to make sure the value was between 0 and 4 (the whole reason I was switching to an enum). Once I dropped the constraint, the ALTER TABLE worked perfectly. I guess I have to gripe about the error message though, it should tell me there was a pr

Re: [GENERAL] Modifying an existing table to use an ENUM instead of an int

2010-06-07 Thread Mike Christensen
Ok, I'm convinced this should work but it does not: CREATE FUNCTION ConvertIntToOrderStateEnum(state integer) RETURNS OrderStateEnum AS $BODY$ SELECT CASE WHEN $1=0 then 'Preview'::OrderStateEnum WHEN $1=1 then 'InQueue'::OrderStateEnum WHEN $1=2 then 'Ordered'::OrderStateEnum WHEN $1=3 t

[GENERAL] Modifying an existing table to use an ENUM instead of an int

2010-06-07 Thread Mike Christensen
Hi all - I have an existing table that looks like this: CREATE TABLE orders ( --Bunch of stuff you don't care about orderstate integer NOT NULL, --Etc ) with a bunch of data in it. I've now created this new data type: CREATE TYPE OrderStateEnum AS ENUM ('Preview', 'InQueue', 'Ordered', '