Re: Two tables refenceing each other's columns

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: GH <grasshacker(at)over-yonder(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Two tables refenceing each other's columns
Date: 2001-01-02 16:39:18
Message-ID: Pine.BSF.4.21.0101020838490.36934-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


You can use ALTER TABLE ADD CONSTRAINT to add foreign key constraints
after table creation.

On Tue, 2 Jan 2001, GH wrote:

>
> Is something like the following allowed (or is not a Bad Idea)?
>
> table1
> ---------+-------------------------
> id1 |serial primary key
> col2 |int references table2(id2)
>
> table2
> ---------+-------------------------
> id2 |serial primary key
> col2 |int references table1(id1)
>
>
> Obviously, creating the tables is a problem since the constraints require
> that the other table exists.
> If doing the above is *not* a Bad Idea, how could I work around this
> problem?
> (That is, (how) can I add the constraints after table creation?
> I imagine something with "create constraint trigger", but the manual is
> not very clear on that.)
>
>
> Thanks
>
> dan
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2001-01-02 16:44:45 Re: pg_dump/psql < db.out issue
Previous Message Zachary Beane 2001-01-02 16:13:21 Re: Re: Possible "off-topic"