pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bruno Wolff III <bruno@wolff.to>
To: Michiel Lange <michiel@minas.demon.nl>
Cc: pgsql-admin@postgresql.org
Subject: Re: Help with triggers
Date: Thu, 26 Feb 2004 08:41:59 -0600
Message-ID: <20040226144159.GA29397@wolff.to> (raw)
In-Reply-To: <403E012D.9070607@minas.demon.nl>
References: <403E012D.9070607@minas.demon.nl>

On Thu, Feb 26, 2004 at 15:22:37 +0100,
  Michiel Lange <michiel@minas.demon.nl> wrote:
> But here it is:
> I have a database that is about how ocomputers and phones are connected 
> in a patch panel.
> For that I have three tables:
> patches(patch_id(serial, pkey), location(varchar, unique));
> computers(computer_id(serial, pkey), name(varchar, unique), patch 
> (unique,references patches.patch_id), ... and some more);
> phones(number(int4, pkey), owner(varchar), patch (unique,references 
> patches.patch_id),  ... and some more);
> 
> (the database is not only about this information, there's quite some 
> more, but this narrows the problem down)
> 
> The point is:
> I can say that computers.patch is unique
> I can also say that phones.patch is unique
> 
> but there's also this situation that you cannot connect a computer and a 
> phone on the same patch_id, so if a patch is used for a computer it is 
> not possible to use that patch also for the phones. (and vise versa)
> As far as I know there is no constraint that enforces this, so I will 
> have to write a trigger...

You can enforce this without having to write a trigger.
You add a patch type to all three tables constrained in patches to be
one of two types and in the other tables to be the type matching that
table. Then you make the foreign keys into patches to be patch_id
combined with the patch type. This prevents both phones and computers
from having the same patch id.



view thread (2+ messages)

Message-ID: <20040226144159.GA29397@wolff.to>
Permalink:  ../20040226144159.GA29397@wolff.to/
Also on:    postgresql.org/message-id/20040226144159.GA29397@wolff.to

 · 

reply

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: bruno@wolff.to, michiel@minas.demon.nl
  Subject: Re: Help with triggers
  In-Reply-To: <20040226144159.GA29397@wolff.to>
  References: <403E012D.9070607@minas.demon.nl> <20040226144159.GA29397@wolff.to>

* 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