Re: implementation of a many-to-many relationship

From: "Dan Langille" <dan(at)langille(dot)org>
To: Dalton Shane <se401029(at)cs(dot)may(dot)ie>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: implementation of a many-to-many relationship
Date: 2002-02-27 15:15:53
Message-ID: 200202271515.g1RFFtk91244@lists.unixathome.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Samuel J. Sutjiono 2002-02-27 15:39:28 System Messages
Previous Message Stephan Szabo 2002-02-27 15:11:21 Re: implementation of a many-to-many relationship