Does anyone know how I can make a constraint on a key to enforce a 1
to n relationship where n>0?
I've invented an example to show the sort of constraint I need:
CREATE TABLE permissions ( id int4, userid int4, perm int4, primary key (id,userid)
);
CREATE TABLE objects ( id int4, perm int4 NOT NULL, data text
);
INSERT INTO permissions (id,userid,perm) VALUES (1,1001,7);
INSERT INTO permissions (id,userid,perm) VALUES (1,1002,6);
INSERT INTO permissions (id,userid,perm) VALUES (1,1003,4);
INSERT INTO permissions (id,userid,perm) VALUES (2,1001,0);
So I want to allow something like:
INSERT INTO objects (id,perm,data) VALUES (1,1,'everyone can read');
INSERT INTO objects (id,perm,data) VALUES (2,1,'everyone can read');
INSERT INTO objects (id,perm,data) VALUES (3,2,'nobody can read');
But disallow an insert like:
INSERT INTO objects (id,perm,data) VALUES (9999,1,'bad perm example');
Is this possible?
-Michael
_________________________________________________________________ http://fastmail.ca/ - Fast Free Web Email for
Canadians