Re: Best practices?

From: David Fetter <david(at)fetter(dot)org>
To: SF Postgres <sfpug(at)postgresql(dot)org>
Subject: Re: Best practices?
Date: 2003-10-01 17:57:48
Message-ID: 20031001175748.GE7302@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: sfpug

On Wed, Oct 01, 2003 at 10:28:35AM -0700, elein wrote:
> A BEFORE trigger is really the way to go here. The trigger function
> would check that the proper number of bars exists or raise an error.
>
> I believe this will work fine both with autocommit and block
> transactions.
>
> The key here is to be sure you enter bars before foos or you will
> never get any valid foos.

Here's what it looks like (modulo the proprietary bits).

CREATE TABLE foo (
foo_id SERIAL PRIMARY KEY
);

CREATE TABLE bar (
bar_id SERIAL PRIMARY KEY
, foo_id INTEGER NOT NULL REFERENCES foo(foo_id)
-- Must have 1 to 4 bars for each foo
-- If 0 bars, delete the foo; don't allow more than 4 bars per foo.
);

Does that explain it a little better?

Cheers,
D
--
David Fetter david(at)fetter(dot)org http://fetter.org/
phone: +1 510 893 6100 cell: +1 415 235 3778

In response to

Responses

Browse sfpug by date

  From Date Subject
Next Message Dror Matalon 2003-10-01 18:36:24 Re: Best practices?
Previous Message elein 2003-10-01 17:28:35 Re: Best practices?