Received: from news.tht.net (news.hub.org [216.126.91.242]) by postgresql.org (8.11.3/8.11.4) with ESMTP id fAM0cEm76395 for ; Wed, 21 Nov 2001 19:38:14 -0500 (EST) (envelope-from news@news.tht.net) Received: (from news@localhost) by news.tht.net (8.11.4/8.11.4) id fAM0PjT74628 for pgsql-sql@postgresql.org; Wed, 21 Nov 2001 19:25:45 -0500 (EST) (envelope-from news) From: lcampos@ics.uci.edu (Luis Miguel Campos) X-Newsgroups: comp.databases.postgresql.sql Subject: primary/foreigner keys Date: 21 Nov 2001 16:11:04 -0800 Organization: http://groups.google.com/ Lines: 27 Message-ID: <5fa15e5f.0111211611.c4dd97b@posting.google.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Complaints-To: groups-abuse@google.com To: pgsql-sql@postgresql.org X-Archive-Number: 200111/341 X-Sequence-Number: 5723 Hi, I am trying to do the following: CREATE TABLE Customer ( customer_id SERIAL PRIMARY KEY; account_id INTEGER UNIQUE REFERENCES Account DEFERRABLE); CREATE TABLE Account ( account_id SERIAL PRIMARY KEY, customer_leader_id INTEGER UNIQUE REFERENCES Customer DEFERRABLE); Description: I am trying to create two tables where several customers can belong to an account and each account has a customer leader. This involves having each tables primary keys to be the foreigner key in the other table. (other solutions are welcome) Problem: First I can not create either table because the other is not known. I tried even within a BEGIN; table creation; commit; Secondly If I succeed how do I INSERT values into the tables? I am sure someone has already faced such a problem, so there must be a solution out there but I could not find it in the postgresql documention. Thank you for your help, Miguel