This alter table is probably terrible performance-wise for a table with millions of rows :-( Also I do not like changing the original table, even if this is only temporary. Notice also that since this is done in a long transaction, we are completely locking the table. Uhm... :-(