Subject Re: [ib-support] changing column type
Author Helen Borrie
At 10:18 PM 8/05/2003 +0000, you wrote:
>Hi, i must change a column type from string to integer.
>Note that the column is PK.
>
>1. Create new column (column1) with same type (string)
>
>2. Put the values from original column to column1
> -> update mytable set column1 = column
>
>3. Change original column type (to integer)

Changing data type from char or varchar to integer ought not to work. Did
you try to commit this change? Did you check the metadata to see whether
it is really integer now?

You must commit after each step. The steps need to be

1. Create new column (column0) of type integer
commit
2. Copy and cast the values from the original column into this column:

--> update mytable set column0 = cast(column as integer);
commit

3. Drop the PK constraint on the original column (first deactivating the
PK's index and any dependencies on it)
commit

4. Recreate the PK column:

alter table mytable add Column integer not null;
commit;

5. Pump the values into it from column0

update mytable set column = column0;
commit;

6. Recreate the PK constraint

commit

7. Drop column0

8. If you like, you can move the PK column back to its original position

alter table mytable
alter column position 1

and commit.

cheers
heLen