Re: Howto change column length

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: bpalmer <bpalmer(at)crimelabs(dot)net>
Cc: DC <danc(at)bspmail(dot)com>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: Howto change column length
Date: 2001-11-06 17:30:31
Message-ID: 20011106092707.E44948-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Tue, 6 Nov 2001, bpalmer wrote:

> > I have a column (ie name varchar(10))
> > and I want to alter it to varchar(20)
> > I've looked throught the docementation and web for examples (no luck),
> > can anyone help?
>
> That can't be done. Once the datatype has been set, it can't be changed
> (how would changing it from 20 to 10 work? how about from varchar to int,
> etc). With the limitation of not being able to drop a column yet, you
> would need to create the new table and copy all the data from one to the

If you're willing to do a little magic to the system tables (and you have
a recent backup :) ). You can change the atttypmod of the column in
question from 14 to 24. This really only works on variable length items
and only to expand them, but...

You pretty much need to do a sequence like:
select oid, relname from pg_class where relname='<tablename>';
update pg_attribute set atttypmod=24 where attrelid=<oid from previous>
and attname='<attributename>'
in a superuser account.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jeff Eckermann 2001-11-06 17:43:27 Re: self outer join
Previous Message Stephan Szabo 2001-11-06 17:22:07 Re: self outer join