From: | Mario Splivalo <mario(dot)splivalo(at)megafon(dot)hr> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | ENUM vs DOMAIN vs FKyed loookup table |
Date: | 2009-04-08 17:08:55 |
Message-ID: | 49DCDA27.4090901@megafon.hr |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
When you need to choose between enum types, domain types or lookup
tables with foreign keys, what do you usualy choose?
Only recently I started using domains, but that seems to be painful, as
Joshua Drake explains here:
For instance, I have an application that tracks codes. I have table that
looks like this:
CREATE TABLE codes (
code_id integer,
code_value integer,
code_type enum_code_type
)
CREATE TYPE enum_code_type AS ENUM
('Unapproved',
'ApprovedByEmail',
'ApprovedByAdmin');
Now, let's say I have around 5.000.000 codes in my table. If I want to
add new code type, i'm in deep pain. I can't do ALTER TYPE to change
enum definition, I need to do hocus-pocus to achieve what I want.
If I used domain, I can do ALTER DOMAIN DROP CONSTRAINT, ALTER DOMAIN
ADD... Takes a bit of time, but it is more flexible than ENUMs.
Joshua made some benchmarking of the enum/domain types, and it turns out
that domain type is slowest one. I'll be posting some of my benchmarks soon.
I abandoned the lookup tables because of the JOINining.
What are your practices, when do you use ENUMs and when Domains?
Mike
From | Date | Subject | |
---|---|---|---|
Next Message | Peter Eisentraut | 2009-04-08 19:42:25 | Re: ENUM vs DOMAIN vs FKyed loookup table |
Previous Message | Stuart McGraw | 2009-04-08 02:47:16 | changing multiple pk's in one update |