Received: from lists.unixathome.org (lists.unixathome.org [210.48.103.158]) by postgresql.org (Postfix) with ESMTP id 25E8B476B47 for ; Wed, 27 Feb 2002 10:15:53 -0500 (EST) Received: from wocker (lists.unixathome.org [210.48.103.158]) by lists.unixathome.org (8.11.6/8.11.6) with ESMTP id g1RFFtk91244; Thu, 28 Feb 2002 04:15:56 +1300 (NZDT) (envelope-from dan@lists.unixathome.org) Message-Id: <200202271515.g1RFFtk91244@lists.unixathome.org> From: "Dan Langille" Organization: DVL Software Limited To: Dalton Shane Date: Wed, 27 Feb 2002 10:15:53 -0500 MIME-Version: 1.0 Subject: Re: implementation of a many-to-many relationship Reply-To: dan@langille.org Cc: pgsql-sql@postgresql.org In-reply-to: <200202271402.OAA23102@cs.may.ie> X-mailer: Pegasus Mail for Windows (v4.01) Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Content-description: Mail message body X-Archive-Number: 200202/433 X-Sequence-Number: 6854 On 27 Feb 2002 at 14:06, Dalton Shane wrote: > I need to implement a many-to-many relationship in PostgreSQL but don't > know how to. I've trawled through the mailing lists but can't find > anything, it's very easy to do in Access so it can't be that hard in > PostgreSQL. > > I created a linking table between two tables (voter, candidates) called > c_voting, I then reference the two table's primary keys to create a > composite primary key for c_voting. > > However when I go to input data into c_voting I get a referential integrity > error saying that the primary key of table voter doesn't match primary key > of c_voting (which it shouldn't). The actual error message would help us. > I've tried everything I can think of for the last four days, but to no > avail. > > This is a central part of my thesis and I need to get it working as soon as > possible. Yeah, well, we all have deadlines. > If anyone knows how to implement this I would be very very very grateful, > I've read all the documentation I can find but it didn't help. > > Many thanks in advance for any advice that you can offer. I created your tables. Then executed the following commands: test=# insert into voter (v_number) values (1); INSERT 1067044 1 test=# insert into candidates (c_number) values (123); INSERT 1067045 1 test=# insert into c_voting values (1, 123); INSERT 1067046 1 test=# select * from c_voting; v_number | c_number ----------+---------- 1 | 123 (1 row) I don't see the problem. Perhaps you should supply your example which fails. Mentioning the postgresql version might be helpful too. These tests were run on 7.2. -- Dan Langille The FreeBSD Diary - http://freebsddiary.org/ - practical examples