pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Markus Wagner <wagner@imsd.uni-mainz.de>
To: pgsql-sql@postgresql.org
Subject: constraints for ensuring relationships
Date: Tue, 21 May 2002 12:08:08 +0200
Message-ID: <0205211208080R.01320@magnus> (raw)

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



view thread (2+ messages)  latest in thread

Message-ID: <0205211208080R.01320@magnus>
Permalink:  ../0205211208080R.01320@magnus/
Also on:    postgresql.org/message-id/0205211208080R.01320@magnus

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: wagner@imsd.uni-mainz.de
  Subject: Re: constraints for ensuring relationships
  In-Reply-To: <0205211208080R.01320@magnus>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox