Skip site navigation (1) Skip section navigation (2)

Re: [SQL] foreign key, create table, and transactions

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Jeffrey Green <jng15(at)columbia(dot)edu>
Cc: <pgsql-sql(at)postgresql(dot)org>, <pgsql-novice(at)postgresql(dot)org>
Subject: Re: [SQL] foreign key, create table, and transactions
Date: 2002-10-18 18:18:22
Message-ID: 20021018111126.Y26317-100000@megazone23.bigpanda.com (view raw or flat)
Thread:
Lists: pgsql-novicepgsql-sql
On Fri, 11 Oct 2002, Jeffrey Green wrote:

> > Hello.  I was wondering if anybody's run across the problem of
> > creating tables with foreign key constraints out of order.  What I
> > mean by this is that say I want a table called <pictures> that has a
> > foreign key reference to a table <people>.  If I define pictures
> > before table, I keep getting an error (Relation "people" doesn't
> > exist).  I tried to group them into a transaction with
> >
> > BEGIN;
> > SET CONSTRAINTS ALL DEFERRED;
> >
> > CREATE TABLE pictures...
> >
> > CREATE TABLE people...
> >
> > COMMIT;
> >
> > But still no.  Is it a requirement of postgres that all creates
> > essentially be "in order" when there are foreign key constraints?

Yes.  The check for the fact that the constraint is valid (as opposed to
the check that the data is valid) is immediate.  You can use alter table
add constraint to add the foreign key constraint after the second table
is created however.


In response to

pgsql-novice by date

Next:From: János LöbbDate: 2002-10-18 22:12:37
Subject: What is the right external type in EOModeler for an internal type integer ?
Previous:From: Tom LaneDate: 2002-10-18 14:11:01
Subject: Re: Vacuum question

pgsql-sql by date

Next:From: Jean-Luc LachanceDate: 2002-10-18 18:24:07
Subject: Re: date
Previous:From: Tom LaneDate: 2002-10-18 18:03:12
Subject: Re: Locking that will delayed a SELECT

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group