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 17:03:57
Message-ID: 20030930170357.GA7302@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: sfpug

Kind people,

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

Responses

Browse sfpug by date

  From Date Subject
Next Message David Fetter 2003-09-30 19:13:00 Best practices?
Previous Message Josh Berkus 2003-09-29 20:35:23 testing, please ignore.