changing the size of a column without dump/restore

From: "Michael Richards" <michael(at)fastmail(dot)ca>
To: pgsql-sql(at)postgresql(dot)org
Subject: changing the size of a column without dump/restore
Date: 2002-11-25 18:57:28
Message-ID: 3DE27298.00009B.07480@ns.interchange.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I've got a huge database table and I need to increase the size of a
varchar from like 100 to 200 characters. As I recall the size is just
a restriction and doesn't actually affect the format of the table
file.

Rather than dumping/restoring a 5Gb table with 20,000,000 rows which
will take all day and night, is there anything I can twiddle in the
system tables to change this size? I'd of course be backing up the
data just in case!

-Michael
_________________________________________________________________
http://fastmail.ca/ - Fast Secure Web Email for Canadians
>From pgsql-sql-owner(at)postgresql(dot)org Mon Nov 25 14:14:59 2002
Received: from localhost (postgresql.org [64.49.215.8])
by postgresql.org (Postfix) with ESMTP id 89DED475BA1
for <pgsql-sql(at)postgresql(dot)org>; Mon, 25 Nov 2002 14:14:56 -0500 (EST)
Received: from brasileiro.net (slxwy.dorms.usu.edu [129.123.227.56])
by postgresql.org (Postfix) with ESMTP id 31DF7475AE4
for <pgsql-sql(at)postgresql(dot)org>; Mon, 25 Nov 2002 14:14:54 -0500 (EST)
Received: from roberto by brasileiro.net with local (Exim 3.35 #1 (Debian))
id 18GOjN-0004xd-00; Mon, 25 Nov 2002 12:17:17 -0700
Date: Mon, 25 Nov 2002 12:17:17 -0700
From: Roberto Mello <rmello(at)cc(dot)usu(dot)edu>
To: Michael Richards <michael(at)fastmail(dot)ca>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: changing the size of a column without dump/restore
Message-ID: <20021125191717(dot)GA19026(at)cc(dot)usu(dot)edu>
References: <3DE27298(dot)00009B(dot)07480(at)ns(dot)interchange(dot)ca>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
In-Reply-To: <3DE27298(dot)00009B(dot)07480(at)ns(dot)interchange(dot)ca>
User-Agent: Mutt/1.4i
X-message-flag: Please consider using an e-mail program other than Outlook. It's insecure.
X-Virus-Scanned: by AMaViS new-20020517
X-Archive-Number: 200211/355
X-Sequence-Number: 10497

On Mon, Nov 25, 2002 at 01:57:28PM -0500, Michael Richards wrote:
> I've got a huge database table and I need to increase the size of a
> varchar from like 100 to 200 characters. As I recall the size is just
> a restriction and doesn't actually affect the format of the table
> file.
>
> Rather than dumping/restoring a 5Gb table with 20,000,000 rows which
> will take all day and night, is there anything I can twiddle in the
> system tables to change this size? I'd of course be backing up the
> data just in case!

PG doesn't have an 'alter table' to increase the column size of a varchar.
But you can accomplish it by manipulating the system tables directly. The size
of a varchar is stored in pg_attribute as the actual size + 4.

For example to change a column "foo" in table "bar" to 200:

update pg_attribute
set atttypmod = 204
where attrelid = ( select oid
from pg_class
where relname = 'bar' )
and attname = 'foo';

-Roberto

P.S: I don't know if this has any bad side effects.

-Roberto

--
+----| Roberto Mello - http://www.brasileiro.net/ |------+
+ Computer Science Graduate Student, Utah State University +
+ USU Free Software & GNU/Linux Club - http://fslc.usu.edu/ +
* JHM wonders what Joey did to earn "I'd just like to say, for the record,
that Joey rules."
-- Seen on #Debian

Browse pgsql-sql by date

  From Date Subject
Next Message greg 2002-11-25 20:22:34 Re: celko nested set functions
Previous Message Tom Lane 2002-11-25 18:32:05 Re: Question on SQL and pg_-tables