From: | Adrian Klaver <aklaver(at)comcast(dot)net> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Cc: | "Phoenix Kiula" <phoenix(dot)kiula(at)gmail(dot)com> |
Subject: | Re: Smartest way to resize a column? |
Date: | 2009-01-12 01:14:40 |
Message-ID: | 200901111714.40810.aklaver@comcast.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Sunday 11 January 2009 5:07:31 pm Phoenix Kiula wrote:
> I am trying to resize a column on a large-ish database (with 5 million
> rows).
>
> The column was 20 characters before, now I want to make it 35 characters.
>
> Challenge is: this is the main indexed column in a busy database.
>
> I tried looking at the ALTER TABLE commands available and there seems
> nothing that allows me to simply change column size from varchar(20)
> to varchar(35)?
>
> So I have this in mind:
>
>
> BEGIN;
> ALTER TABLE users ADD COLUMN name_new varchar(35);
> UPDATE users SET name_new = name;
> ALTER TABLE users DROP COLUMN name;
> ALTER TABLE users RENAME COLUMN name_new TO name;
> COMMIT;
>
>
> I guess this would work, but I am wondering if there is a nicer way to
> do this that doesn't involve a new column, copying, then dropping old
> column?
>
> Thanks!
ALTER TABLE users ALTER COLUMN name_new TYPE varchar(35)
--
Adrian Klaver
aklaver(at)comcast(dot)net
From | Date | Subject | |
---|---|---|---|
Next Message | Phoenix Kiula | 2009-01-12 01:21:46 | Re: Smartest way to resize a column? |
Previous Message | Ian Barwick | 2009-01-12 01:12:23 | Re: Smartest way to resize a column? |