Re: Fw: Change column data type - Mailing list pgsql-sql

From scott.marlowe
Subject Re: Fw: Change column data type
Date
Msg-id Pine.LNX.4.33.0309040912510.27003-100000@css120.ihs.com
Whole thread Raw
In response to Fw: Change column data type  ("Kumar" <sgnerd@yahoo.com.sg>)
List pgsql-sql
On Tue, 2 Sep 2003, Kumar wrote:

> 
> Dear Friends,
> 
> Using Postgres 7.3.4 over the linux server 7.3. 
> 
> Is it possible to alter/change the data type of a existing table's 
> column, with out dropping and recreating a column of same name.

Only for certain types, and only by hacking the system catalogs, which is 
a procedure fraught with danger.  i.e. backup all your data, then proceed 
with caution.

Generally, it's best to create a new column and put the data in there and 
drop the old column.  Note you can do this in a transaction, so you can 
roll it back should you realize you've made some kind of error.

begin;
alter table t1 add column c1 int8;
update t1 set c1=c2;
alter table t1 drop column c2;
commit;
vacuum;



pgsql-sql by date:

Previous
From: sad
Date:
Subject: pg_type and type names
Next
From: "Senthil Kumar S"
Date:
Subject: Change column data type