Re: Composite UNIQUE across two tables?

From: Jorge Godoy <jgodoy(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Composite UNIQUE across two tables?
Date: 2008-03-07 02:22:27
Message-ID: 200803062322.27911.jgodoy@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Em Thursday 06 March 2008 22:10:14 Jamie Tufnell escreveu:
>
> I already have site_id in the users table and I can determine the
> site_group_id from that. So it seems redundant to me, to store
> site_group_id for each user as well. Also, I'm not sure how I would
> enforce that the site_group_id added to the users table would
> correspond correctly with the site_id (as per the sites table).
> Perhaps I would make a composite foreign key?

Or you manage site_group_id from a trigger. When the user creates / chooses a
site_id and updates/inserts this information then you fill site_group_id with
a trigger. This way you guarantee the correctness of this parameter.

> I've never come up against this situation before, and because of the
> reasons above, I'm getting the feeling there might be a better way to
> design this.

Again, a trigger can do that. Slower than denormalizing the database, but it
can be done.

--
Jorge Godoy <jgodoy(at)gmail(dot)com>

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Bart Degryse 2008-03-07 07:46:24 Re: Composite UNIQUE across two tables?
Previous Message Jamie Tufnell 2008-03-07 01:10:14 Re: Composite UNIQUE across two tables?