Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 08FAF475C26 for ; Thu, 19 Dec 2002 06:28:19 -0500 (EST) Received: from serwer.skawsoft.com.pl (serwer.skawsoft.com.pl [213.25.37.66]) by postgresql.org (Postfix) with ESMTP id 1E16A4758E1 for ; Thu, 19 Dec 2002 06:28:18 -0500 (EST) Received: from klaster.net (pk17.krakow.cvx.ppp.tpnet.pl [217.99.211.17]) by serwer.skawsoft.com.pl (Postfix) with ESMTP id 912B72B85B; Thu, 19 Dec 2002 12:11:48 +0100 (CET) Message-ID: <3E01ADF1.5050003@klaster.net> Date: Thu, 19 Dec 2002 12:30:57 +0100 From: Tomasz Myrta User-Agent: Mozilla/5.0 (Windows; U; Win 9x 4.90; en-US; rv:1.2b) Gecko/20021016 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Gary Stainburn Cc: pgsql-sql@postgresql.org Subject: Re: references table(multiple columns go here) References: <200212181625.11316.gary.stainburn@ringways.co.uk> <200212190928.19736.gary.stainburn@ringways.co.uk> <3E019829.204@klaster.net> <200212191030.11661.gary.stainburn@ringways.co.uk> In-Reply-To: <200212181625.11316.gary.stainburn@ringways.co.uk> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200212/234 X-Sequence-Number: 10822 Gary Stainburn wrote: > On Thursday 19 Dec 2002 9:58 am, Tomasz Myrta wrote: > > >Gary Stainburn wrote: > > > >>That did the trick. However, I now have another problem with the > >>constraint > >>complaining about there not being an index to refer to. However, > >>there is. The error is inside declaration of table "ranks. You can't create two similiar foreign keys: one based on field (rrank) and second one based on fields (rdid,rrank). You have to change: jrank int4 not null references ranks(rrank), -- needs sorting to jrank int4 not null, -- needs sorting > This is probably because of my background in as a COBOL programmer where > having multiple fields of the same name can cause problems (especially > with > MF Cobol which only partially supports it) as well as early (read > early 80's) > database experince where it wasn't allowed. Also, I find it usefull > because > I know immediately which table a field has come from. As you wish. > > > Why does it make joins easier to use the same name for fields? If you create queries like this, you get rid of duplicates. select * from jobtypes join departments using (did) If you are afraid of duplicates, you can always use an alias: select ranks.rank_id as rid, ... If you want, here is my minimal version of your tables: create table depts ( dept_id int4 primary key, ... }; create table ranks ( rank_id int4 default nextval('ranks_rid_seq') primary key, dept_id int4 references depts, -- department rank int4 not null, -- departmental rank rdesc character varying(40) -- Rank Description ); create table jobtypes ( jobtype_id int4 default nextval('jobs_jid_seq') primary key, rank_id int4 references ranks(rank_id), jdesc character varying(40) -- job description ); Tomasz Myrta