From: Richard Poole <rp@guests.deus.net>
To: pgsql-admin@postgresql.org
Subject: Re: Multiple keys?
Date: Wed, 28 Aug 2002 14:36:48 +0100
Message-ID: <20020828133648.GA18842@guests.deus.net> (raw)
In-Reply-To: <200208280634.55534.cshobe@secureworks.net>
References: <200208280210.44746.cshobe@secureworks.net>
<20020828102247.GA23727@guests.deus.net>
<200208280634.55534.cshobe@secureworks.net>
On Wed, Aug 28, 2002 at 06:34:55AM -0400, Casey Allen Shobe wrote:
> On Wednesday 28 August 2002 06:22 am, Richard Poole wrote:
> > Your two-column constraint, the one you need to add to get your foreign
> > key working, implies your three-column one. So you can just get rid of
> > the three-column one.
>
> Hmm, that's a problem :\. See I want the table to be constrained by a unique
> combination of the three, but I want the second table to be constrained by a
> unique combination of only the two, as the third column is not present in the
> second table.
>
> I'm uncertain what to do, but I thank you for pointing out my error in
> overconstraining the first table.
You could do it with one more table, perhaps?
CREATE TABLE package_versions (
package_id integer NOT NULL REFERENCES packages,
package_version varchar(16) NOT NULL DEFAULT '0.0.1',
UNIQUE(package_id, package_version)
);
CREATE TABLE package_info (
package_id integer NOT NULL,
package_version varchar(16) NOT NULL,
info_type varchar(32) NOT NULL DEFAULT 'extra_data',
-- other fields
FOREIGN KEY (package_id, package_version) REFERENCES package_versions,
UNIQUE (package_id, package_version, info_type)
);
CREATE TABLE box_packages (
package_id integer NOT NULL,
package_version varchar(16) NOT NULL,
-- other fields
FOREIGN KEY (package_id, package_version) REFERENCES package_versions,
-- other constraints
);
Does that do what you need?
Richard
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-admin@postgresql.org
Cc: rp@guests.deus.net
Subject: Re: Multiple keys?
In-Reply-To: <20020828133648.GA18842@guests.deus.net>
References: <200208280210.44746.cshobe@secureworks.net> <20020828102247.GA23727@guests.deus.net> <200208280634.55534.cshobe@secureworks.net> <20020828133648.GA18842@guests.deus.net>
* 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