Re: Evolving databases (eg deleting columns) - Mailing list pgsql-general

From Andrew Sullivan
Subject Re: Evolving databases (eg deleting columns)
Date
Msg-id 20020726102228.B18001@mail.libertyrms.com
Whole thread Raw
In response to Evolving databases (eg deleting columns)  ("Christian H. Stork" <cstork@ics.uci.edu>)
List pgsql-general
On Thu, Jul 25, 2002 at 05:19:18PM -0700, Christian H. Stork wrote:

> My question: How can I evolve databases (ie deleting columns,
> adding/changing/removing constraints, etc)?

You can use ALTER TABLE for adding & removing constraints.  But you
can't delete columns.

You can leave the columns in, however.  You can add a new column,
renaming the former column to something new (like colname_dead), and
name the new column to the name of the original column.  Then do

    UPDATE table SET colname=colname_dead;
    UPDATE table SET colname_dead=NULL;

Then, make that column null always.  There's very little overhead
attached to a column with all nulls (4 bytes?  I think that's it.
There's a map that needs to be maintained, but that's it).

A

--
----
Andrew Sullivan                               87 Mowat Avenue
Liberty RMS                           Toronto, Ontario Canada
<andrew@libertyrms.info>                              M6K 3E3
                                         +1 416 646 3304 x110


pgsql-general by date:

Previous
From: "Marc G. Fournier"
Date:
Subject: Re: Bad HTML in Mail List Archives
Next
From: Justin Clift
Date:
Subject: Re: Bad HTML in Mail List Archives