Re: Tables referencing each other - Mailing list pgsql-general

From Tom Lane
Subject Re: Tables referencing each other
Date
Msg-id 11698.1071866538@sss.pgh.pa.us
Whole thread Raw
In response to Tables referencing each other  (Felix Finch <felix@crowfix.com>)
List pgsql-general
Felix Finch <felix@crowfix.com> writes:
> CREATE TABLE xyzzy (a INT PRIMARY KEY, b INT REFERENCES plugh);
> CREATE TABLE plugh (c INT PRIMARY KEY, d INT REFERENCES xyzzy);

> I can't actually do this in 7.4, so I had to create the first table
> without the reference.

> Is it possible to pre-declare the second table, similar to a C
> prototype, so the first definition would not complain about the second
> table being unknown?

No.  What you do is create the tables, then ALTER TABLE ADD FOREIGN KEY.

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: DB & Log Files removed...
Next
From: Tom Lane
Date:
Subject: Re: Salvage older PostgreSQL data disk - help?