Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id B9290476B38 for ; Wed, 18 Dec 2002 11:34:55 -0500 (EST) Received: from stan.ringways.co.uk (hub.ringways.co.uk [213.38.87.130]) by postgresql.org (Postfix) with ESMTP id A3B16476298 for ; Wed, 18 Dec 2002 11:31:02 -0500 (EST) Received: from gary.ringways.co.uk ([10.1.1.2]) by stan.ringways.co.uk with esmtp (Exim 3.22 #1) id 18Oh4n-0005Ir-00 for pgsql-sql@postgresql.org; Wed, 18 Dec 2002 16:29:41 +0000 Content-Type: text/plain; charset="us-ascii" From: Gary Stainburn Organization: Ringways Garages Ltd To: pgsql-sql@postgresql.org Subject: references table(multiple columns go here) Date: Wed, 18 Dec 2002 16:25:11 +0000 User-Agent: KMail/1.4.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-Id: <200212181625.11316.gary.stainburn@ringways.co.uk> X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200212/223 X-Sequence-Number: 10811 Hi folks, how do I define a referene from 2 columns in 1 table to 2 columns in another. I have: create table ranks ( rid int4 default nextval('ranks_rid_seq'::text) unique not null, rdid character references depts(did), -- department rrank int4 not null, -- departmental rank rdesc character varying(40) -- Rank Description ); create unique index "ranks_drank_index" on ranks using btree ("rdid", "rrank"); copy "ranks" from stdin; 1 O 1 Trainee TTI 2 O 2 TTI 3 M 1 Cleaner 4 M 2 Passed Cleaner 5 M 3 Fireman. \. I would now like to define the following table so that inserts can only happen if jdid matches rdid and jrank matches rrank. create table jobtypes ( jid int4 default nextval('jobs_jid_seq'::text) unique not null, jdid character references ranks(rdid), -- This joint reference jrank int4 not null references ranks(rrank), -- needs sorting jdesc character varying(40) -- job description ); copy "jobtypes" from stdin; 1 M 3 Charge Cleaner 2 O 3 Lock Carriages \. (I want the first row to work and the second to be rejected) -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investigatory Powers Act, 2000