From: Michael Richards <michael@fastmail.ca>
To: pgsql-sql@postgresql.org
Subject: changing the size of a column without dump/restore
Date: Mon, 25 Nov 2002 13:57:28 -0500 (EST)
Message-ID: <3DE27298.00009B.07480@ns.interchange.ca> (raw)
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@postgresql.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@postgresql.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@postgresql.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@cc.usu.edu>
To: Michael Richards <michael@fastmail.ca>
Cc: pgsql-sql@postgresql.org
Subject: Re: changing the size of a column without dump/restore
Message-ID: <20021125191717.GA19026@cc.usu.edu>
References: <3DE27298.00009B.07480@ns.interchange.ca>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
In-Reply-To: <3DE27298.00009B.07480@ns.interchange.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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: michael@fastmail.ca
Subject: Re: changing the size of a column without dump/restore
In-Reply-To: <3DE27298.00009B.07480@ns.interchange.ca>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox