From: | Mike Christensen <mike(at)kitchenpc(dot)com> |
---|---|
To: | "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Modifying an existing table to use an ENUM instead of an int |
Date: | 2010-06-07 07:11:01 |
Message-ID: | AANLkTimdgYrjWRhydTETZeImcZT1jW1TFQLEhht7tXKd@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
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',
'Error', 'Cancelled');
I want to change the type of "orderstate" from integer to
OrderStateEnum, and cast 0 to Preview, 1 to InQueue, 2 to Ordered,
etc.
I could create a new column, copy all the data over, then delete the
old column, but I suspect there's some cool way to go about doing
this. Thanks!
Mike
PS - This is totally shameless, but if you cook or your spouse does,
I'd totally appreciate it if you could take a short survey to help us
develop this website we're working on. We're hoping to get about a
thousand responses so I have to plug it everywhere :) This URL is
http://survey.kitchenpc.com/
From | Date | Subject | |
---|---|---|---|
Next Message | Mike Christensen | 2010-06-07 07:40:22 | Re: Modifying an existing table to use an ENUM instead of an int |
Previous Message | Craig Ringer | 2010-06-07 06:44:25 | Re: Error on Windows server could not open relation base/xxx/xxx Permission denied |