Re: Changing data types - Mailing list pgsql-hackers

From Hannu Krosing
Subject Re: Changing data types
Date
Msg-id 3BAF50AD.5A060EC5@tm.ee
Whole thread Raw
In response to Re: Changing data types  ("Gowey, Geoffrey" <ggowey@rxhope.com>)
List pgsql-hackers
"Gowey, Geoffrey" wrote:
> 
> One thought did just occur to me.  It is at least theoretically possible to
> simplisticly migrate on column type to another by reading in the data and
> oid of the row into a struct, drop the column, create a new column with the
> correct data type, and populate.  This is ugly, but it is better than saying
> "no, you can't".

The DROP COLUMN part is the one that is what's really hard. 

It is not currently supported in postgreSQL

Supporting it comes up now and then, but as the solution (changing
system tables 
and then rewriting the whole table) is considered ugly in current
implementation
it has always windled down to not doing it.

The way to manually change column type is something like:

alter table mytable add column newcolumn int;
update table set newcolumn = oldcolumn;
alter table rename oldcolumn to __del__001;
alter table rename newcolumn to oldcolumn;


but you can't DROP COLUMN without recreating the TABLE

------------
Hannu


pgsql-hackers by date:

Previous
From: Hannu Krosing
Date:
Subject: Re: Changing data types
Next
From: Stephan Szabo
Date:
Subject: Re: [SQL] outer joins strangeness