From: Jorge Godoy <jgodoy@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Re: Composite UNIQUE across two tables?
Date: Thu, 6 Mar 2008 23:22:27 -0300
Message-ID: <200803062322.27911.jgodoy@gmail.com> (raw)
In-Reply-To: <b0a4f3350803061710y2d3391cdwa54d7dcf4af5692f@mail.gmail.com>
References: <b0a4f3350803061104s89656bcl739e1aa1cdcb6e3a@mail.gmail.com>
<CMEFJOLLJJDJKKLGEJJMGEJDCAAA.ray@madigans.org>
<b0a4f3350803061710y2d3391cdwa54d7dcf4af5692f@mail.gmail.com>
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@gmail.com>
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: jgodoy@gmail.com
Subject: Re: Composite UNIQUE across two tables?
In-Reply-To: <200803062322.27911.jgodoy@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox