Altering live databases - Mailing list pgsql-sql

From Gregory Brauer
Subject Altering live databases
Date
Msg-id 3D51950D.7090004@wildbrain.com
Whole thread Raw
Responses Re: Altering live databases  ("Christopher Kings-Lynne" <chriskl@familyhealth.com.au>)
List pgsql-sql
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



pgsql-sql by date:

Previous
From: "Ross J. Reedstrom"
Date:
Subject: Re: running psql in a cron job
Next
From: "Christopher Kings-Lynne"
Date:
Subject: Re: ALTER TABLE follow up