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 17:03:57
Message-ID: 20030930170357.GA7302@fetter.org (view raw or flat)
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

sfpug by date

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

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