Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id AD48F475D70 for ; Mon, 25 Nov 2002 14:00:48 -0500 (EST) Received: from mail.interchange.ca (ns.interchange.ca [216.126.79.2]) by postgresql.org (Postfix) with ESMTP id 0EBA4475C45 for ; Mon, 25 Nov 2002 14:00:48 -0500 (EST) Received: by mail.interchange.ca (Fastmailer, from userid 555) id 4F3B9251D; Mon, 25 Nov 2002 13:57:28 -0500 (EST) Received: from 24.43.130.241 by www.fastmail.ca with HTTP; Mon, 25 Nov 2002 18:57:28 +0000 (UTC) MIME-Version: 1.0 Message-Id: <3DE27298.00009B.07480@ns.interchange.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) From: "Michael Richards" X-Fastmail-IP: [24.43.130.241] X-Virus-Scanned: by AMaViS new-20020517 Content-Transfer-Encoding: 7bit Content-Type: Text/Plain X-Archive-Number: 200211/354 X-Sequence-Number: 10496 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 ; 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 ; 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 To: Michael Richards 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