1

You can rename a column using the following statement:

ALTER TABLE table_name RENAME COLUMN column_name TO new_column_name;

However, this brings the old column out of commission immediately. Any use sites that used the old column name will start having problems.

Is there a way to put the table into a transitory state in which both the old and new name can be used to refer to the column, so that I can move over my clients and then afterwards decommission the old name?

2
  • 4
    You could rename the table and create a view with the (original) name of the table that returns both columns.
    – user1822
    Oct 27, 2020 at 15:03
  • You will have to restrict operations with data for some time, which is necessary to change the source codes of sites: before - old name is used for all operations; during - SELECT by both names allowed, INSERT/UPDATE which sets the value for either old or new name not allowed; after - new name is used for all operations.
    – Akina
    Oct 27, 2020 at 17:46

1 Answer 1

4

Rename the column, add a generated column with the old name. If inserts or updates of the old column haven't been corrected yet, provide insert and update triggers to handle the new column. When no logic refers to the old column anymore, drop it.

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.