What are best practices around adding new columns to tables? How do people usually do this since non-NULL defaults aren't allowed?
What are best practices around adding new columns to tables? How do people usually do this since non-NULL defaults aren't allowed?
There are a few steps:
NOT NULL
constraint, you can do it (assuming you've actually populated every row). If you have other processes that are adding rows in parallel, then those processes will need to be updated to also populate your new column, else you'll be playing a never-ending game of catch-up. Note that, when aNOT NULL
constraint is added, cloud spanner initiates a background process to validate your data (i.e. checks that all cells are not null) before actually finalizing the schema change. More info on data validation is here.More info is here.