Re: Adding foreign key constraints without integrity check? - Mailing list pgsql-general

From Florian G. Pflug
Subject Re: Adding foreign key constraints without integrity check?
Date
Msg-id 449728BE.4080005@phlo.org
Whole thread Raw
In response to Re: Adding foreign key constraints without integrity check?  (louis gonzales <gonzales@linuxlouis.net>)
Responses Re: Adding foreign key constraints without integrity check?
List pgsql-general
louis gonzales wrote:
> Florian,
> Are you certain:
>
> "You can only create an FK if the fields you are referencing in the
> foreign table form a PK there. And creating a PK implicitly creates an
> index, which you can't drop without dropping the PK :-("
>
Arg.. Should have written "unique index" instead of primary key..
But it doesn't change much, since a unique index and a pk are nearly
the same.

> I'm not sure I am convinced the necessity of a foreign key, "needing" to
> reference a primary keyed entry from a different table.
I tried the following:
create table a(id int4) ;
create table b(id int4, a_id int4) ;
alter table b add constraint pk foreign key (a_id) references a (id) ;

The alter table gave me an error stating that I need to have a unique index
defined on a.id...

greetings, Florian Pflug

pgsql-general by date:

Previous
From: Jerry LeVan
Date:
Subject: psql for winxp?
Next
From: Casey Duncan
Date:
Subject: Re: Cannot restart postgres