Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 8F6354763F0; Fri, 18 Oct 2002 14:18:26 -0400 (EDT) Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) by postgresql.org (Postfix) with ESMTP id D29494761B2; Fri, 18 Oct 2002 14:18:22 -0400 (EDT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id AC58AD5F7; Fri, 18 Oct 2002 11:18:22 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id A21ED5C02; Fri, 18 Oct 2002 11:18:22 -0700 (PDT) Date: Fri, 18 Oct 2002 11:18:22 -0700 (PDT) From: Stephan Szabo To: Jeffrey Green Cc: , Subject: Re: [SQL] foreign key, create table, and transactions In-Reply-To: Message-ID: <20021018111126.Y26317-100000@megazone23.bigpanda.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200210/181 X-Sequence-Number: 5020 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 that has a > > foreign key reference to a table . 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.