pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stephan Szabo <sszabo@megazone23.bigpanda.com>
To: Jeffrey Green <jng15@columbia.edu>
Cc: pgsql-sql@postgresql.org
Cc: pgsql-novice@postgresql.org
Subject: Re: [SQL] foreign key, create table, and transactions
Date: Fri, 18 Oct 2002 11:18:22 -0700 (PDT)
Message-ID: <20021018111126.Y26317-100000@megazone23.bigpanda.com> (raw)
In-Reply-To: <F823415B-DCE7-11D6-B141-000393675CB6@columbia.edu>

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.




view thread (2+ messages)

Message-ID: <20021018111126.Y26317-100000@megazone23.bigpanda.com>
Permalink:  ../20021018111126.Y26317-100000@megazone23.bigpanda.com/
Also on:    postgresql.org/message-id/20021018111126.Y26317-100000@megazone23.bigpanda.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: sszabo@megazone23.bigpanda.com, jng15@columbia.edu, pgsql-novice@postgresql.org
  Subject: Re: [SQL] foreign key, create table, and transactions
  In-Reply-To: <20021018111126.Y26317-100000@megazone23.bigpanda.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