Let's say I have a field called A of type CHAR and a field called B of type INT.

I'm migrating field A to a new type by creating a new field and copying the values around. The field is called B.

At the moment the two field coexist while I am copying the data from a column to another and the application code has a fallback so if column B contains a value then return B, otherwise return the value from A and convert the value at the application level.

The Problem

Now I would like to rename B to A but I'm finding it really difficult to find a solution that doesn't require many deploys by creating another temp column and doing a switch of columns again.


Is there anyway where I can say something like select (int(A) or B) as B from table?

Or do you have any ideas on making this a little bit smoother?


1 Answer 1


No you caqn't have two columns with the same name.

What you can do is

CREATE TABLE tab1(a char(2), b INT)
ALTER TABLE tab1 CHANGE a a1 char(2)
ALTER TABLE tab1 CHANGE b a int;
ALTER TABLE tab1 CHANGE a1 b char(2)
b  |  a
:- | -:
1  |  5

db<>fiddle here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.