Re: Fw: Change column data type

From: "scott(dot)marlowe" <scott(dot)marlowe(at)ihs(dot)com>
To: Kumar <sgnerd(at)yahoo(dot)com(dot)sg>
Cc: psql <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Fw: Change column data type
Date: 2003-09-04 15:16:01
Message-ID: Pine.LNX.4.33.0309040912510.27003-100000@css120.ihs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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;

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Rod Taylor 2003-09-04 19:50:28 Re: MINUS & ROWNUM in PostGres
Previous Message sad 2003-09-04 10:56:03 pg_type and type names