Thanks to visit codestin.com
Credit goes to postgrespro.com

Re: Alter table - Mailing list pgsql-sql

From scott.marlowe
Subject Re: Alter table
Date
Msg-id [email protected]
Whole thread Raw
In response to Alter table  ("David" <[email protected]>)
List pgsql-sql
On Wed, 10 Mar 2004, David wrote:

> Ok another very newbie question. How can i change the data type a column can
> accept? at the moment it will only take character(7) i want to change it to
> varchar(30), but i cant figure how, ideas?

While there are ways to tinker with the system catalogs to change between 
different text types / lengths, none of these are "officially supported" 
and may well screw up your database if you do something wrong.  I believe 
the archives likely have this question over and over in them.

The proper way to do this is to make a new column, put the old column in 
it, and then drop the old column:

create table test (a char(7));
insert a few thousand lines to test...;
begin;
alter table test add column b varchar(30);
update test set b=a;
alter table test drop column a;
commit; (or rollback; should things go horribly wrong...)
vacuum full test;




pgsql-sql by date:

Previous
From: Robert Treat
Date:
Subject: Re: designer tool connect to PostgreSQL
Next
From: Andreas Joseph Krogh
Date:
Subject: Inserting data in a table using sub-selects