Re: Changing the type of a column in an already populated

From: "scott(dot)marlowe" <scott(dot)marlowe(at)ihs(dot)com>
To: Brian Minton <bminton(at)efn(dot)org>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: Changing the type of a column in an already populated
Date: 2002-11-22 16:06:50
Message-ID: Pine.LNX.4.33.0211220902330.25220-100000@css120.ihs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, 21 Nov 2002, Brian Minton wrote:

> David Pradier wrote:
> > Hi!
> >
> > I'd like to know if it is possible to change the type of a column to a
> > compatible one, in an already populated database.
> > For example, changing a column from varchar(20) to varchar(25) ?
> > I'm using postgresql 7.3rc1
> >
> > Thanks for your help.
> >
> > Best regards,
> > David
>
> dump the database, edit the dump file, and reload. of course, this is
> annonying on live data, but it works

The other method, which works well on tables with no triggers or fks or
anything, which is common when you're first building tables and such:

create table test (name varchar(20), id int, bucks numeric(12,2));
(insert some data, play around...)
begin;
select name::varchar(32), id, bucks into test2 from test;
drop table test;
alter table test2 rename to test;
commit;

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Don Isgitt 2002-11-22 16:11:38 Lack of use of indexes
Previous Message Brandon Craig Rhodes 2002-11-22 15:51:12 Re: improving a badly optimized query