Re: Alter table

From: "scott(dot)marlowe" <scott(dot)marlowe(at)ihs(dot)com>
To: David <de4(at)kent(dot)ac(dot)uk>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Alter table
Date: 2004-03-10 17:55:47
Message-ID: Pine.LNX.4.33.0403101052100.10418-100000@css120.ihs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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;

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Robert Treat 2004-03-10 18:18:26 Re: designer tool connect to PostgreSQL
Previous Message David 2004-03-10 17:17:01 Changing primary keys