Re: Table design - unknown number of column

From: Sean Davis <sdavis2(at)mail(dot)nih(dot)gov>
To: pgsql-general(at)postgresql(dot)org, Richard Ollier <r(dot)ollier(at)tequila(dot)co(dot)jp>
Subject: Re: Table design - unknown number of column
Date: 2006-11-09 13:13:11
Message-ID: 200611090813.11651.sdavis2@mail.nih.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I think the typical way of attacking a problem would be a second and third
table. The second table would look like:

flat_type table
flag_type_id
flag_type (like the column name in your original table)
flag_type_description (BONUS: you can describe each flag)

product_flag table
product_id (fk to your original table)
flag_type_id (fk to the flag_type table)
flag_value (0, 1, or whatever you want to store here)

The advantages with this method are several:
1) No wasted storage for all those NULLs where a flag is not needed
2) Should be very fast to lookup by product_id to get all flags
3) You can expand to an arbitrary number of flags
4) Your schema remains normalized

Sean

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2006-11-09 13:17:37 Re: autovacuum blues
Previous Message Richard Ollier 2006-11-09 12:45:50 Re: Table design - unknown number of column