Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 7EEF64761DC for ; Thu, 19 Dec 2002 06:43:51 -0500 (EST) Received: from stan.ringways.co.uk (hub.ringways.co.uk [213.38.87.130]) by postgresql.org (Postfix) with ESMTP id 37627476E98 for ; Thu, 19 Dec 2002 06:43:35 -0500 (EST) Received: from gary.ringways.co.uk ([10.1.1.2]) by stan.ringways.co.uk with esmtp (Exim 3.22 #1) id 18Oz4F-0002to-00; Thu, 19 Dec 2002 11:42:19 +0000 Content-Type: text/plain; charset="iso-8859-1" From: Gary Stainburn Organization: Ringways Garages Ltd To: Tomasz Myrta Subject: Re: references table(multiple columns go here) Date: Thu, 19 Dec 2002 11:37:38 +0000 User-Agent: KMail/1.4.3 Cc: pgsql-sql@postgresql.org References: <200212181625.11316.gary.stainburn@ringways.co.uk> <200212191030.11661.gary.stainburn@ringways.co.uk> <3E01ADF1.5050003@klaster.net> In-Reply-To: <3E01ADF1.5050003@klaster.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-Id: <200212191137.38284.gary.stainburn@ringways.co.uk> X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200212/235 X-Sequence-Number: 10823 On Thursday 19 Dec 2002 11:30 am, Tomasz Myrta wrote: > 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 Oops, thought I'd removed that one. Sorry. Thanks for all the help here. SQL's a totally different thought process to anything I'm used to, but I'm getting there slowly. > > > 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) I see your point. Maybe I'll have to rethink a bit. As I said, I'm having to do a lot of rethinking. > > 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 -- 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