changing column type

From: "Claudio Lapidus" <clapidus(at)hotmail(dot)com>
To: <pgsql-general(at)postgresql(dot)org>
Subject: changing column type
Date: 2003-08-01 20:17:01
Message-ID: BAY7-DAV23CrsAWABNv000110a4@hotmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I need to modify a column which is currently defined as varchar(30) to
varchar(40). I can see from the docs (and trial) that I cannot directly
alter a column this way, so I intend to do the following:

ALTER TABLE t1 ADD COLUMN duplicate varchar(40);
UPDATE t1 SET duplicate=original;
ALTER TABLE t1 DROP COLUMN original;
ALTER TABLE t1 RENAME duplicate TO original;

But I'm worried about messing up things if I run this queries while the
database is live, i.e. there are other processes writing to the table. Now,
if I enclose the above into a BEGIN/COMMIT pair, would you say it is safe to
run concurrently with other transactions?

TIA,
cl.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Roger Hand 2003-08-01 20:46:54 Monthly table partitioning for fast purges?
Previous Message Mat Proud 2003-08-01 19:40:08 pg_stat_activity