changing column type - Mailing list pgsql-general

From Claudio Lapidus
Subject changing column type
Date
Msg-id BAY7-DAV23CrsAWABNv000110a4@hotmail.com
Whole thread Raw
Responses Re: changing column type  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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.


pgsql-general by date:

Previous
From: Francisco J Reyes
Date:
Subject: Domains (Was [PERFORM] Views With Unions)
Next
From: Mat Proud
Date:
Subject: pg_stat_activity