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

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
      joining column's datatypes do not match

Reply via email to