Home > Mobile >  How to copy SQL column data to new column then drop the original column?
How to copy SQL column data to new column then drop the original column?

Time:07-09

I am following the recommendation in this sql snowflake forum in order to transform an integer data column into a varchar by creating a new column. I want to drop the original integer column when I am done, but doing so always results in the new column no longer working and any future queries erroring out.

For instance, I have test_num is the integer and test_num_to_char is the varchar

alter table test_table 
    add test_num_to_char varchar as CAST(test_num as varchar)

then

alter table test_table 
    drop column test_num

select * 
from test_table

results in an error message:

SQL execution internal error: Processing aborted due to error 300002:224117369

Is there a different transformation method that removes the dependency on the original integer column so I can drop it?

CodePudding user response:

alter table test_table add test_num_to_char varchar(10);
go

update test_table set test_num_to_char = CAST(recno as varchar);

CodePudding user response:

Try the TO_DECIMAL transformation method.

It's documentation is given here

  • Related