From: Leif Biberg Kristensen <leif@solumslekt.org>
To: pgsql-sql@postgresql.org
Subject: DDL problems: Referential issue?
Date: Wed, 4 Nov 2009 19:03:36 +0100
Message-ID: <200911041903.36563.leif@solumslekt.org> (raw)
PostgreSQL 8.3.8 on Gentoo Linux.
I've got a junction table:
CREATE TABLE participants (
person_fk INTEGER REFERENCES persons (person_id),
event_fk INTEGER REFERENCES events (event_id) ON DELETE CASCADE,
sort_order INTEGER NOT NULL DEFAULT 1,
is_principal BOOLEAN NOT NULL DEFAULT TRUE,
PRIMARY KEY (person_fk, event_fk)
);
CREATE INDEX event_key ON participants (event_fk);
CREATE INDEX person_key ON participants (person_fk);
Now I want to add some text to a few participants, but as this will probably
only be for a few per cent, I try to create an extra table like this:
pgslekt=> CREATE TABLE participant_notes (
pgslekt(> person_fk INTEGER NOT NULL REFERENCES participants
(person_fk),
pgslekt(> event_fk INTEGER NOT NULL REFERENCES participants (event_fk)
ON DELETE CASCADE,
pgslekt(> part_note TEXT,
pgslekt(> PRIMARY KEY (person_fk, event_fk)
pgslekt(> );
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index
"participant_notes_pkey" for table "participant_notes"
ERROR: there is no unique constraint matching given keys for referenced table
"participants"
I fail to see what is the problem. I even tried to add a unique constraint to
participants:
pgslekt=> alter table participants add constraint unique_person_event unique
(person_fk, event_fk);
NOTICE: ALTER TABLE / ADD UNIQUE will create implicit index
"unique_person_event" for table "participants"
ALTER TABLE
But I still get the same error message as above.
This works fine, naturally:
pgslekt=> CREATE TABLE participant_notes (
pgslekt(> person_fk INTEGER NOT NULL references persons (person_id),
pgslekt(> event_fk INTEGER NOT NULL references events (event_id) ON
DELETE CASCADE,
pgslekt(> part_note TEXT,
pgslekt(> PRIMARY KEY (person_fk, event_fk)
pgslekt(> );
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index
"participant_notes_pkey" for table "participant_notes"
CREATE TABLE
However, I think that this table should reference participants, not the
primary tables persons and events.
--
Leif Biberg Kristensen
http://solumslekt.org
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: leif@solumslekt.org
Subject: Re: DDL problems: Referential issue?
In-Reply-To: <200911041903.36563.leif@solumslekt.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox