Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: ALTER COLUMN TYPE general for column that has a check constraint not supported. #48288

Open
RichardJCai opened this issue May 1, 2020 · 0 comments
Assignees
Labels
A-schema-changes A-sql-pgcompat Semantic compatibility with PostgreSQL C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)

Comments

@RichardJCai
Copy link
Contributor

RichardJCai commented May 1, 2020

Currently, ALTER COLUMN TYPE for a column that has a check constraint is not supported.

Steps to implement:

  1. 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.
  2. Need to check if constraint is valid (aka casts are valid and comparisons can be done), otherwise fail schema change.
  3. After swapping the column, need to drop constraints for old column.
  4. 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

@RichardJCai RichardJCai added C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) A-sql-pgcompat Semantic compatibility with PostgreSQL labels May 1, 2020
@RichardJCai RichardJCai self-assigned this May 1, 2020
@exalate-issue-sync exalate-issue-sync bot added the T-sql-schema-deprecated Use T-sql-foundations instead label Oct 21, 2022
@exalate-issue-sync exalate-issue-sync bot added T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) and removed T-sql-schema-deprecated Use T-sql-foundations instead labels May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-schema-changes A-sql-pgcompat Semantic compatibility with PostgreSQL C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants