Re: What is the good equivalent for ENUM ?

From: Joseph Hepburne Healy <j(dot)healy(at)ugrad(dot)unimelb(dot)edu(dot)au>
To: Ron Johnson <ron(dot)l(dot)johnson(at)cox(dot)net>
Cc: PgSQL General ML <pgsql-general(at)postgresql(dot)org>
Subject: Re: What is the good equivalent for ENUM ?
Date: 2003-09-04 02:24:54
Message-ID: Pine.OSF.4.10.10309041215050.17891-100000@cassius.its.unimelb.edu.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, 3 Sep 2003, Ron Johnson wrote:

> It'll be better when domains have alterable constraints. Your
> way is the traditional (and best, IMO) way, though.

This is similar to what I have tended to use, but I have always wondered
about the efficency, and have used an int4 serial column as the primary
key and used this to reference the status data.

This has made it a little frustrating sometimes to write queries though.
Is referencing the varchar column generally reasonable in postgresql, and
not likely to give big performance issues as the tables get larger?
(sorry, this is a little hand wavy and not very exact, but I am wondering
if i am getting carried away giving everything an id)

This is the type of thing I have used: (edited from a couple of posts ago)

> > CREATE TABLE status_levels (
> > status_levels_id serial primary key,
status varchar(10)
> > ) 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 int4 NOT NULL DEFAULT 1 REFERENCES
status_levels(status_levels_id),
> > ...
> > );
> >

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2003-09-04 02:29:47 Re: Comparing dates
Previous Message Tom Lane 2003-09-04 02:00:19 Re: postmaster crashing