Re: unique constraints - Mailing list pgsql-sql

From Michael Fuhr
Subject Re: unique constraints
Date
Msg-id 20040107103147.A11576@quality.qadas.com
Whole thread Raw
In response to unique constraints  (Kenneth Gonsalves <lawgon@thenilgiris.com>)
Responses Re: unique constraints
List pgsql-sql
On Wed, Jan 07, 2004 at 07:47:32PM +0530, Kenneth Gonsalves wrote:
> in 7.4 i'm getting an error message - UNIQUE constraint matching keys for 
> table 'xxx' not found - any clues?

It would be helpful to see the *exact* wording of the error message and
the SQL statements that can be used to reproduce the error.

I'd guess that you tried to create a foreign key constraint whose
referenced column(s) didn't have a UNIQUE constraint:

=> CREATE TABLE foo (foo_id INTEGER NOT NULL);
CREATE TABLE
=> CREATE TABLE bar (foo_id INTEGER NOT NULL REFERENCES foo (foo_id));
ERROR:  there is no unique constraint matching given keys for referenced table "foo"

The referenced column(s) should either be a PRIMARY KEY or have a UNIQUE
constraint:

=> CREATE TABLE foo (foo_id INTEGER PRIMARY KEY);
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "foo_pkey" for table "foo"
CREATE TABLE
=> CREATE TABLE bar (foo_id INTEGER NOT NULL REFERENCES foo (foo_id));
CREATE TABLE

See the "Foreign Keys" documentation for more info:

http://www.postgresql.org/docs/current/static/ddl-constraints.html#DDL-CONSTRAINTS-FK

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/


pgsql-sql by date:

Previous
From: Andreas
Date:
Subject: Notation of index
Next
From: "Rodrigo Sakai"
Date:
Subject: Importation wtih copy generated some wrong registers..