Re: Length of Varchar - Mailing list pgsql-admin

From Ian Barwick
Subject Re: Length of Varchar
Date
Msg-id 200301240926.45780.barwick@gmx.net
Whole thread Raw
In response to Length of Varchar  (Andre Schubert <andre@km3.de>)
Responses Re: Length of Varchar  (Ian Barwick <barwick@gmx.net>)
List pgsql-admin
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



> I have search the idocs and found some docs about the system-table
> pg_attribute, where the length of a varchar-field is stored in atttypmod.
> Is it possible to change the value of atttypmod and is it safe to change
> this value?

Possible but probably not safe. No doubt someone will be along shortly
with a more accurate opinion ;-).

Ian Barwick
barwick@gmx.net


pgsql-admin by date:

Previous
From: Andre Schubert
Date:
Subject: Length of Varchar
Next
From: Ian Barwick
Date:
Subject: Re: Length of Varchar