Re: extensible enum types - Mailing list pgsql-hackers

From Peter Geoghegan
Subject Re: extensible enum types
Date
Msg-id AANLkTim2Zzn9vs_AusOBXt-LIJFZFlYv88aetunBXJJf@mail.gmail.com
Whole thread Raw
In response to Re: extensible enum types  ("Joshua D. Drake" <jd@commandprompt.com>)
List pgsql-hackers
> Ahem. That is what a natural key is for :)

Well, they have their own drawbacks that don't make them particularly
appealing to use with lookup tables to ape enums. How many lookup
tables have you seen in the wild with a natural key?

People sometimes represent things like US states as enums. This is
probably a mistake, because you cannot control or predict if there'll
be a new US state, unlikely though that me be. You *can* control, for
example, what types of payment your application can deal with, and
you'll probably have to hardcode differences in dealing with each
inside your application, which makes enums a good choice. In my
earlier example, in addition to 'cash', there is a value for
payment_type of 'credit_card' . There is a separate column in the
payments table that references a credit_cards table, because credit
cards are considered transitory. A check constraint enforces that
credit_cards_id is null or not null as appropriate.

I don't like the idea of having values in a table that aren't so much
data as an integral part of your application/database. I think it's
wrong-headed. That's why I am not in favour of your enums as a lookup
table wrapper suggestion.

-- 
Regards,
Peter Geoghegan


pgsql-hackers by date:

Previous
From: "Kevin Grittner"
Date:
Subject: Re: beta3 & the open items list
Next
From: "Kevin Grittner"
Date:
Subject: Re: extensible enum types