Modifying an existing table to use an ENUM instead of an int
| От | Mike Christensen |
|---|---|
| Тема | Modifying an existing table to use an ENUM instead of an int |
| Дата | |
| Msg-id | AANLkTimdgYrjWRhydTETZeImcZT1jW1TFQLEhht7tXKd@mail.gmail.com обсуждение исходный текст |
| Ответы |
Re: Modifying an existing table to use an ENUM instead of an int
|
| Список | 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/
В списке pgsql-general по дате отправления: