best way to handle enum type

From: Tom Hart <tomhart(at)coopfed(dot)org>
To: Postgres General List <pgsql-general(at)postgresql(dot)org>
Subject: best way to handle enum type
Date: 2007-11-21 23:13:19
Message-ID: 4744BB8E.9010308@coopfed.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hey everybody. I have a field that, in my earlier mySQL days would have
been an enum('q','y','m','c'), and I'm wondering what's the best way to
handle this in pgsql. I've googled enough to find out that pgsql doesn't
have a built in enum type (it's of course possible that what I read was
outdated, please let me know if it was), but I've found a couple popular
workarounds, the first being

CHECK (favourite_colour IN ('red', 'blue', 'yellow', 'purple'))

as well as a suggestion to create another small table containing the
possible values and then placing

color text references color

in the create table sql. Now this field doesn't absolutely have to be an
enum, I'm sure I could work with matching the values to numbers and
making it an int. What I'm wondering is what's generally considered
'best practice' for this situation. I'd like to have a solid db more
than an enum type, what's my best move?

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Selena Deckelmann 2007-11-21 23:30:18 POLL: Women-sized t-shirts for PostgreSQL
Previous Message Raymond O'Donnell 2007-11-21 22:53:08 Re: Coordinating database user accounts with active directory