Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id A41104768D5 for ; Tue, 3 Dec 2002 11:43:00 -0500 (EST) Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) by postgresql.org (Postfix) with ESMTP id BF373476918 for ; Tue, 3 Dec 2002 11:31:33 -0500 (EST) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id B62CDD60C; Tue, 3 Dec 2002 08:31:35 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id ABDFD5C02; Tue, 3 Dec 2002 08:31:35 -0800 (PST) Date: Tue, 3 Dec 2002 08:31:35 -0800 (PST) From: Stephan Szabo To: Tomasz Myrta Cc: Subject: Re: recreating table and foreign keys In-Reply-To: <20021203170324.M63387@klaster.net> Message-ID: <20021203082926.W71171-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: 200212/36 X-Sequence-Number: 10624 On Tue, 3 Dec 2002, Tomasz Myrta wrote: > Hi > I use Postgresql 7.2.2. > Sometimes I have to remove a column from my tables (psql): > 1. alter table master_table rename to x; > 2. \i tables.sql > 3. insert into master_table select f1,f2,... from x > 4. drop table x > > I think, foreign keys referring from detail_table(s) to master_table > have gone. > How to recreate foreign keys? I want to keep my database in better > integrity, than now... You'll probably end up using ALTER TABLE ADD CONSTRAINT to add the constraints to the new master_table. It's possible that you might be able to hack something with the system tables, but that sounds dangerous. Or you can upgrade to 7.3 which lets you run alter table drop column. :)