custom integrity check - Mailing list pgsql-general

From Abdul-Wahid Paterson
Subject custom integrity check
Date
Msg-id 995fcdb005012103586e15d9fc@mail.gmail.com
Whole thread Raw
Responses Re: custom integrity check  (Peter Eisentraut <peter_e@gmx.net>)
Re: custom integrity check  (Michael Kleiser <mkl@webde-ag.de>)
List 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

pgsql-general by date:

Previous
From: Marco Colombo
Date:
Subject: Re: Multiline plpython procedure
Next
From: Marco Colombo
Date:
Subject: Re: Multiline plpython procedure