google-cloud-platformddlgoogle-cloud-spanner

Cloud Spanner Rename Column


I am attempting to rename a table column in cloud spanner. Is there a way to do this without creating a new column, coping the old values and then dropping the old column? Reading through the cloud spanner documentation it is unclear if this operation is possible. The only way I can get this to work is with the DDL statement and intermediate DML SQL:

ALTER TABLE my_table ADD COLUMN col_name STRING(1024);
-- Between these steps make a DML statement to copy the data over before dropping the old table
ALTER TABLE my_table DROP COLUMN new_col_name;
ALTER TABLE my_table ALTER COLUMN new_col_name STRING(1024) NOT NULL;

Solution

  • There are some limitations on schema changes: