pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Chris Czeyka <czeyka@skwea.co.jp>
To: pgsql-sql@postgresql.org
To: pgsql-general@postgresql.org
Subject: two tables - foreign keys referring to each other...
Date: Wed, 21 Feb 2001 12:30:51 +0900
Message-ID: <3A93366B.DC0B83F4@skwea.co.jp> (raw)

Hey to all,

I got two tables, linked to each other. How can I tell the first CREATE TABLE
(institute_t) to wait to check the foreign key for the second table??? just
like "hold on a little bit... you'll receive your admin_t" :-) ? I thoght
DEFERRABLE, DEFERRED and transaction with BEGIN/COMMIT take care of this.

..or generally: how do you create two crosslinked foreign keyed tables?

hopefully an easy problem for the real professionals!


-----------------> here we go
BEGIN; -- begin table transaction -- Only Postgresql
CREATE TABLE institute_t (
        name            VARCHAR(48) PRIMARY KEY,
        street          VARCHAR(48) NOT NULL,
        zip             VARCHAR(16),
        town            VARCHAR(32) NOT NULL,           
        country         CHAR(2) NOT NULL, /* country codes ISO-3166*/
        phone           VARCHAR(32) NOT NULL,
        fax             VARCHAR(32),
        admin           VARCHAR(16) REFERENCES admin_t
                ON UPDATE CASCADE
                ON DELETE SET NULL
                DEFERRABLE
                INITIALLY DEFERRED
);

CREATE TABLE admin_t (
        login           VARCHAR(16) PRIMARY KEY,
        password        VARCHAR(16) NOT NULL,
        email           VARCHAR(32) NOT NULL,
        real_name       VARCHAR(32) NOT NULL,
        street          VARCHAR(48) NOT NULL,
        zip             VARCHAR(16),
        town            VARCHAR(32) NOT NULL,           
        country         CHAR(2) NOT NULL, /* country codes -- refer to
ISO-3166*/
        phone           VARCHAR(32) NOT NULL,
        fax             VARCHAR(32),
        access          INTEGER NOT NULL,
        institute       VARCHAR(48) REFERENCES institute_t
                ON UPDATE CASCADE
                ON DELETE SET NULL
                DEFERRABLE
                INITIALLY DEFERRED
);
COMMIT;


of course I get the ERROR, that admin_t doesn't exist. So? help the stupid!
pls!

best greets,
Chris



view thread (8+ messages)  latest in thread

Message-ID: <3A93366B.DC0B83F4@skwea.co.jp>
Permalink:  ../3A93366B.DC0B83F4@skwea.co.jp/
Also on:    postgresql.org/message-id/3A93366B.DC0B83F4@skwea.co.jp

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: czeyka@skwea.co.jp, pgsql-general@postgresql.org
  Subject: Re: two tables - foreign keys referring to each other...
  In-Reply-To: <3A93366B.DC0B83F4@skwea.co.jp>
  References: <3A93366B.DC0B83F4@skwea.co.jp>

* 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