pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Fuhr <mike@fuhr.org>
To: Kenneth Gonsalves <lawgon@thenilgiris.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: unique constraints
Date: Wed, 7 Jan 2004 10:31:47 -0700
Message-ID: <20040107103147.A11576@quality.qadas.com> (raw)
In-Reply-To: <0401071947320T.02497@thenilgiris.com>
References: <0401071947320T.02497@thenilgiris.com>

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/



view thread (3+ messages)  latest in thread

Message-ID: <20040107103147.A11576@quality.qadas.com>
Permalink:  ../20040107103147.A11576@quality.qadas.com/
Also on:    postgresql.org/message-id/20040107103147.A11576@quality.qadas.com

 · 

reply

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: mike@fuhr.org, lawgon@thenilgiris.com
  Subject: Re: unique constraints
  In-Reply-To: <20040107103147.A11576@quality.qadas.com>

* 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