Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id 7565D475A42 for ; Tue, 21 May 2002 05:54:43 -0400 (EDT) Received: from yara.imsd.uni-mainz.de (yara.IMSD.Uni-Mainz.DE [134.93.144.68]) by postgresql.org (Postfix) with ESMTP id 8C0EB4758FE for ; Tue, 21 May 2002 05:54:41 -0400 (EDT) Received: (from smap@localhost) by yara.imsd.uni-mainz.de (8.9.3/8.9.3/lxs_5.2) id LAA04296 for ; Tue, 21 May 2002 11:54:52 +0200 Received: from hermes.imsd.uni-mainz.de(134.93.64.80) by yara.imsd.uni-mainz.de via smap (V2.1/2.1+anti-relay+anti-spam) id xma004286; Tue, 21 May 02 11:54:47 +0200 Received: from magnus (unverified [134.93.64.112]) by hermes.imsd.uni-mainz.de (EMWAC SMTPRS 0.83) with SMTP id ; Tue, 21 May 2002 11:46:54 +0200 Content-Type: text/plain; charset="iso-8859-15" From: Markus Wagner Organization: IMBEI To: pgsql-sql@postgresql.org Subject: constraints for ensuring relationships Date: Tue, 21 May 2002 12:08:08 +0200 X-Mailer: KMail [version 1.2] MIME-Version: 1.0 Message-Id: <0205211208080R.01320@magnus> Content-Transfer-Encoding: 8bit X-Archive-Number: 200205/216 X-Sequence-Number: 7851 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