constraints for ensuring relationships

From: Markus Wagner <wagner(at)imsd(dot)uni-mainz(dot)de>
To: pgsql-sql(at)postgresql(dot)org
Subject: constraints for ensuring relationships
Date: 2002-05-21 10:08:08
Message-ID: 0205211208080R.01320@magnus
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi,

I wonder if I can use constraints to ensure some special integrity.

Suppose there is a table "Type" of item types:

CREATE TABLE "Type"
(
"index" SERIAL PRIMARY KEY,
"name" TEXT,
"multiple" BOOL
);

Suppose there is a table "Item" like this:

CREATE TABLE "Item"
(
"index" SERIAL PRIMARY KEY,
"type" INT REFERENCES "Type",
"data" TEXT
);

Supose there is a table "SubItem" that contains special details about our
items:

CREATE TABLE "SubItem"
(
"index" SERIAL PRIMARY KEY,
"Item" INT REFERENCES "Item",
"Data" TEXT
);

And now the constraint:

Each Item should be allowed to have more than one subitem, if and only if its
type allows for multiple instances, i. e. the type the item is linked to must
have 't' in its field 'multiple'.

Can I attach constraints to some of the tables (e. g. "SubItem") that ensure
this?

Thanks a lot!

Markus

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Bruno Wolff III 2002-05-21 11:54:42 Re: Guarantee uniqueness of PGP key
Previous Message Wolfgang.Fuertbauer 2002-05-21 07:12:51 drop constraint problem