custom integrity check

From: Abdul-Wahid Paterson <abdulwahid(at)gmail(dot)com>
To: abdulwahd(at)gmail(dot)com
Cc: pgsql-general(at)postgresql(dot)org
Subject: custom integrity check
Date: 2005-01-21 11:58:25
Message-ID: 995fcdb005012103586e15d9fc@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

I have the following table as a link table between my 'cats' table and
my 'items' table. Every item must have at least one cat and exactly
one 'master' cat.

How can I create an integrity check to make sure that each item has
exactly one 'master' cat.

CREATE TABLE cats_items (
cat_id int4 NOT NULL,
item_id int4 NOT NULL,
master boolean DEFAULT 'f',
FOREIGN KEY (cat_id) REFERENCES cats (cat_id),
FOREIGN KEY (item_id) REFERENCES items (item_id),
PRIMARY KEY (cat_id, item_id)
);

Thanks,

Abdul-Wahid

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Marco Colombo 2005-01-21 12:40:06 Re: Multiline plpython procedure
Previous Message Marco Colombo 2005-01-21 11:02:09 Re: Multiline plpython procedure