pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedforeign key, create table, and transactions
2+ messages / 2 participants
[nested] [flat]
* foreign key, create table, and transactions
@ 2002-10-11 07:06 Jeffrey Green <jng15@columbia.edu>
0 siblings, 1 reply; 2+ messages in thread
From: Jeffrey Green @ 2002-10-11 07:06 UTC (permalink / raw)
To: pgsql-sql; +Cc: pgsql-novice@postgresql.org
> 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?
> Please cc a response to jng15 at columbia dot edu. Thanks so much.
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: [SQL] foreign key, create table, and transactions
@ 2002-10-18 18:18 Stephan Szabo <sszabo@megazone23.bigpanda.com>
parent: Jeffrey Green <jng15@columbia.edu>
0 siblings, 0 replies; 2+ messages in thread
From: Stephan Szabo @ 2002-10-18 18:18 UTC (permalink / raw)
To: Jeffrey Green <jng15@columbia.edu>; +Cc: pgsql-sql; pgsql-novice@postgresql.org
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.
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2002-10-18 18:18 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-10-11 07:06 foreign key, create table, and transactions Jeffrey Green <jng15@columbia.edu>
2002-10-18 18:18 ` Stephan Szabo <sszabo@megazone23.bigpanda.com>
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