Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id C5655633847 for ; Wed, 4 Nov 2009 14:03:48 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 87942-10 for ; Wed, 4 Nov 2009 18:03:41 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail43.e.nsc.no (mail43.e.nsc.no [193.213.115.43]) by mail.postgresql.org (Postfix) with ESMTP id 8C2CC633DD5 for ; Wed, 4 Nov 2009 14:03:39 -0400 (AST) Received: from balapapa.localnet (42.185.16.62.customer.cdi.no [62.16.185.42]) (authenticated bits=0) by mail43.nsc.no (8.14.3/8.14.3) with ESMTP id nA4I3bhP029251 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Wed, 4 Nov 2009 19:03:37 +0100 (MET) From: Leif Biberg Kristensen To: pgsql-sql@postgresql.org Subject: DDL problems: Referential issue? Date: Wed, 4 Nov 2009 19:03:36 +0100 User-Agent: KMail/1.12.1 (Linux/2.6.27-gentoo-r10; KDE/4.3.1; i686; ; ) MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <200911041903.36563.leif@solumslekt.org> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200911/11 X-Sequence-Number: 33362 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