Skip site navigation (1) Skip section navigation (2)

Best practices?

From: David Fetter <david(at)fetter(dot)org>
To: SF Postgres <sfpug(at)postgresql(dot)org>
Subject: Best practices?
Date: 2003-09-30 19:13:00
Message-ID: 20030930191300.GA8274@fetter.org (view raw or flat)
Thread:
Lists: sfpug
Kind people,

Please pardon me if this is a repost--my messing with procmail has
messed up a few things.  Anyhow...

It's fairly common to have a situation like

"A foo may have one or more bars," as in

CREATE TABLE foo (
  foo_id SERIAL PRIMARY KEY
);

CREATE TABLE bar (
  bar_id SERIAL PRIMARY KEY
)

CREATE TABLE foo_bar (
  foo_id INTEGER NOT NULL REFERENCES foo(foo_id) ON DELETE RESTRICT
, bar_id INTEGER NOT NULL REFERENCES bar(bar_id) ON DELETE RESTRICT
);

What I'd like to do is a more general:

For integers 0 <= m <= n <= infinity,

At the end of any transaction involving foo (including INSERT), a foo
must have between m and n bars.

Is there a standard way to approach this?

TIA for any pointers :)

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

sfpug by date

Next:From: Josh BerkusDate: 2003-10-01 05:38:48
Subject: Re: Best practices?
Previous:From: David FetterDate: 2003-09-30 17:03:57
Subject: Best practices?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group