Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 6CE69476067 for ; Fri, 24 Jan 2003 05:35:13 -0500 (EST) Received: from lubitsch.akademie.de (ns.akademie.de [62.165.4.3]) by postgresql.org (Postfix) with ESMTP id AF911476410 for ; Fri, 24 Jan 2003 05:34:50 -0500 (EST) Received: from [62.165.4.177] (helo=kidman.akademie1.de) by lubitsch.akademie.de with esmtp (Exim 3.33 #2) id 18c1Ai-0005a6-00; Fri, 24 Jan 2003 11:34:52 +0100 Content-Type: text/plain; charset="utf-8" From: Ian Barwick To: Andre Schubert , pgsql-admin@postgresql.org Subject: Re: Length of Varchar Date: Fri, 24 Jan 2003 11:33:33 +0100 User-Agent: KMail/1.4.3 References: <20030124073709.7f2b1524.andre@km3.de> <200301240926.45780.barwick@gmx.net> In-Reply-To: <200301240926.45780.barwick@gmx.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-Id: <200301241133.33319.barwick@gmx.net> X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200301/266 X-Sequence-Number: 7108 On Friday 24 January 2003 09:26, Ian Barwick wrote: > On Friday 24 January 2003 07:37, Andre Schubert wrote: > > i have a little question on changing the length of a varchar field. > > Is there another way than dump and reload if i want to change the length > > of a varchar field ? > > in 7.3: > > BEGIN; > ALTER TABLE foo RENAME your_field TO your_field_old; > ALTER TABLE foo ADD COLUMN your_field VARCHAR([new length]); > UPDATE foo SET your_field=your_field_old; > ALTER TABLE foo DROP COLUMN your_field_old; > COMMIT; > > In 7.3, if the new column is shorter you may need to truncate the values > being inserted. > > In versions < 7.3 you will not be able to drop the old column; there you > may want to recreate the table, there's a techdoc article here: > http://techdocs.postgresql.org/techdocs/updatingcolumns.php Addendum: Someone has written me a private email pointing out that if you do recreate a table like this, dependent views etc. will no longer work, and asks if there is any way around this apart from upgrading to 7.3. I think the short answer is "no". (As in there's "no such thing as a free lunch" ;-) Ian Barwick barwick@gmx.net