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: only allow altering a column type when an assignment cast is allowed #115442

Merged
merged 1 commit into from Jan 2, 2024

Conversation

andrew-delph
Copy link
Contributor

@andrew-delph andrew-delph commented Dec 1, 2023

Fixes: #82416

Release note (sql change): Reject changing column types unless an explicitly cast is provided where cannot automatically cast. This replicates logic in Postgres. Prior to this change, casts such as BOOL to INT were possible without explicitly casting.

@andrew-delph andrew-delph requested a review from a team as a code owner December 1, 2023 19:08
Copy link

blathers-crl bot commented Dec 1, 2023

Thank you for contributing to CockroachDB. Please ensure you have followed the guidelines for creating a PR.

My owl senses detect your PR is good for review. Please keep an eye out for any test failures in CI.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@blathers-crl blathers-crl bot added the O-community Originated from the community label Dec 1, 2023
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link

blathers-crl bot commented Dec 1, 2023

Thank you for updating your pull request.

My owl senses detect your PR is good for review. Please keep an eye out for any test failures in CI.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@rafiss rafiss requested review from mgartner and a team December 1, 2023 20:53
Copy link
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for your contribution!

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @andrew-delph and @mgartner)


-- commits line 9 at r1:
nit: "postures" -> "postgres"


pkg/sql/alter_column_type.go line 342 at r1 (raw file):

		// Validate that the column can be automatically cast to toType without explicit casting.
		if validCast := cast.ValidCast(col.GetType(), toType, cast.ContextAssignment); !validCast {
			return pgerror.WithCandidateCode(

nit: use this constructor:

return errors.WithHintf(  
  pgerror.Newf(  
   pgcode.DatatypeMismatch,  
   "column %q cannot be cast automatically to type %s",  
   col.GetName(),  
   toType.SQLString(),  
  ),  "You might need to specify \"USING %s\".", s,  
)

@andrew-delph
Copy link
Contributor Author

Looks like there are failing UTs, so I will take a look.

…owed

Fixes: cockroachdb#82416

Release note (sql change): Reject changing column
types unless an explicitly cast is provided where
cannot automatically cast. This replicates logic
in postgres. Prior to this change, casts such as
BOOL to INT were possible without explicitly
casting.
@yuzefovich
Copy link
Member

Friendly ping @mgartner

Copy link
Collaborator

@mgartner mgartner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution! :lgtm:

Reviewed 1 of 2 files at r1, 1 of 1 files at r2, 4 of 4 files at r3, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @andrew-delph and @rafiss)

Copy link
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

bors r+

@craig
Copy link
Contributor

craig bot commented Jan 2, 2024

Build succeeded!

And happy new year! 🎉

@craig craig bot merged commit 736a529 into cockroachdb:master Jan 2, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-community Originated from the community
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sql: only allow altering a column type when an assignment cast is allowed
5 participants