Open
Description
Currently, ALTER COLUMN TYPE for a column that has a check constraint is not supported.
Steps to implement:
- On creation of new column, copy constraints and create constraint for new column. Each comparison to the column has to be casted to the new type. Comparisons that have the column inside a nested expression must also be converted.
- For example, if (x INT) has check (x + 5 > 10), after float conversion, the constraint would be (x + 5::float > 10::float).
-pg source code for re-adding constraint
- For example, if (x INT) has check (x + 5 > 10), after float conversion, the constraint would be (x + 5::float > 10::float).
- Need to check if constraint is valid (aka casts are valid and comparisons can be done), otherwise fail schema change.
- After swapping the column, need to drop constraints for old column.
- Need to rename the constraints during/after the swap since we can't have duplicate constraint names if we want to keep the constraint name the same.
Example:
If the original column constraint was (x > 0),
after a cast to string, the new constraint should be (x > 0::string).
This is postgres behaviour.
Jira issue: CRDB-4338
Epic CRDB-44826