From: | Dennis Gearon <gearond(at)fireserve(dot)net> |
---|---|
To: | Vivek Khera <khera(at)kcilink(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: What is the good equivalent for ENUM ? |
Date: | 2003-09-03 15:50:18 |
Message-ID: | 3F560DBA.4060001@fireserve.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
that's how I'd do it, since in reality, that's all an ENUM is, is a mini
foreign table internalized onto a column in another table.
Vivek Khera wrote:
>>>>>>"SD" == Shridhar Daithankar <shridhar_daithankar(at)persistent(dot)co(dot)in> writes:
>>>>>>
>>>>>>
>
>SD> On 3 Sep 2003 at 14:30, Bruno BAGUETTE wrote:
>
>
>>>The problem is that this MySQL database uses ENUM, do you see what can I
>>>do to migrate ENUM into PostgreSQL ?
>>>
>>>
>
>SD> varchar with check constraints. Add constraits to allow only
>SD> certain values of varchar string.
>
>I used to do this. It turns out to be horribly inflexible when you
>need to alter the enum values since the constraints cannot easily be
>changed.
>
>What I do is create a short table for the enum like this:
>
>CREATE TABLE status_levels (
> status varchar(10) PRIMARY KEY
>) WITHOUT OIDS;
>INSERT INTO status_levels (status) VALUES ('active');
>INSERT INTO status_levels (status) VALUES ('overdue');
>INSERT INTO status_levels (status) VALUES ('suspended');
>INSERT INTO status_levels (status) VALUES ('terminated');
>
>then reference it via foreign key from the "enum" field:
>
>CREATE TABLE whatever (
> ...
>?status varchar(10) NOT NULL DEFAULT 'active' REFERENCES status_levels(status),
> ...
>);
>
>
>
>
>
>
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2003-09-03 16:05:58 | Re: pg_dump incorrect sequence value |
Previous Message | Dennis Gearon | 2003-09-03 15:46:42 | Re: Using oids |