Re: Reference to multiple cols

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Josh Berkus <josh(at)agliodbs(dot)com>
Cc: Ville Jungman <ville_jungman(at)hotmail(dot)com>, pgsql-novice(at)postgresql(dot)org
Subject: Re: Reference to multiple cols
Date: 2003-01-12 00:51:21
Message-ID: 20030112005121.GA13716@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Sat, Jan 11, 2003 at 14:00:14 -0800,
Josh Berkus <josh(at)agliodbs(dot)com> wrote:
>
> This should give you a system in which animal_id is the primary key for
> each table, and therefore there is a one-for-one relationship between
> the animal table and each of the dog and cat tables, and would prevent
> you from deleting a referenced record from the animal table.
>
> You would need an additional trigger to prevent duplication *between*
> the dog and cat tables.

There is a way to do this without triggers. You add an animal type
field to all of the tables. The foreign keys then should use both animal id
and animal type (which means you need to make animal_id and animal_type
a combined unique key on the animal table). You add a constraint to the animal
specific tables forcing the animal type to be the appropiate type.

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Rod Kreisler 2003-01-12 04:27:08 ERROR: NEW used in non-rule query
Previous Message Ville Jungman 2003-01-11 23:20:06 Re: Reference to multiple cols