Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 82D02475B4A for ; Wed, 7 Aug 2002 18:07:23 -0400 (EDT) Received: from wildbrain.com (w211.z065104009.sjc-ca.dsl.cnc.net [65.104.9.211]) by postgresql.org (Postfix) with ESMTP id 35B764758BB for ; Wed, 7 Aug 2002 17:45:59 -0400 (EDT) Received: from wildbrain.com (spock.wildbrain.com [10.20.2.38]) by wildbrain.com (8.12.2/8.12.2) with ESMTP id g77LjniQ022420 for ; Wed, 7 Aug 2002 14:45:58 -0700 Message-ID: <3D51950D.7090004@wildbrain.com> Date: Wed, 07 Aug 2002 14:45:49 -0700 From: Gregory Brauer User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.0) Gecko/20020529 X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Altering live databases Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200208/138 X-Sequence-Number: 8984 I am starting to do a test run of maintaining a live database, and I'm trying to figure out how to add a relation to an existing table. Lets say I do: CREATE TABLE something ( id serial , ); And later I decide I *really* wish I had done: CREATE TABLE something ( id serial , foo_id int4 not null, foreign key(foo_id) references foo(id) on update CASCADE, ); How can I update a live database to add the missing relation? So far I know that I need to: ALTER TABLE issue_transaction ADD COLUMN foo_id int4 not null; But how do I declare the foreign key and how do I declare the ON UPDATE? Is this something that is better done from a backup? I've noticed the trigger syntax in a backup isn't exactly friendly, and the TOC Entry IDs are numbered, but I woudn't know what number to use to create a new one. Advice? Greg