Re: New DB-design - help and documentation pointers appreciated

From: Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
To: Rikard Bosnjakovic <rikard(dot)bosnjakovic(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: New DB-design - help and documentation pointers appreciated
Date: 2010-07-21 02:25:21
Message-ID: 4C465A91.80200@postnewspapers.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 20/07/10 18:14, Rikard Bosnjakovic wrote:

> However, I feel that this design is the same design I seem to use for
> all my databases, and in the end I always find that I designed them
> wrong from the beginning. The table "components" feels like that one
> is going to be locked into a corner; it seems to "fixed" and not as
> flexible as I want this database to be.

Flexibility in storing and structuring data isn't a strong point of SQL
databases. That said, there *are* some workarounds. I've mentioned EAV
and why it's ... ugly.

A potentially superior option I didn't think to mention before is
hstore. You can use a hstore field to store key/value "extension" data
that isn't easy to model in a generic relational way without landing up
with hundreds of tiny tables. See:

http://www.postgresql.org/docs/8.4/static/hstore.html

That way you can store the common stuff in a typical relational form for
easy querying and manipulation, but can fall back to key/value for
hard-to-model attributes that might be quite specific to particular
classes of component.

I guess you could even have your subcategories carry a column that
listedrequired hstore keys as an array, so that you could require that
all components of a particular subtype have a certain list of hstore keys.

(I often wish SQL would see some extensions to support a more ...
flexible ... representation of data. SQL is great for accessing purely
relational data, but it'd be so nice to be able to break the relational
mould where required without having to replace the entire database
system just because some of your data doesn't quite fit. There are
workarounds of a sort (EAV - ugh!, hstore, etc) but the lack of
convenient language support limits them somewhat.)

--
Craig Ringer

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Craig Ringer 2010-07-21 02:52:31 Re: Problem with pg_try_advisory_lock and two connections (seemingly) getting the same lock
Previous Message Brett Hoerner 2010-07-20 23:27:46 Problem with pg_try_advisory_lock and two connections (seemingly) getting the same lock