-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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: "char" is supposed to truncate long values #66422
sql: "char" is supposed to truncate long values #66422
Conversation
Thank you for contributing to CockroachDB. Please ensure you have followed the guidelines for creating a PR. Before a member of our team reviews your PR, I have some potential action items for you:
I have added a few people who may be able to assist in reviewing: 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks! one small improvement
pkg/sql/sem/tree/casts.go
Outdated
@@ -434,6 +436,12 @@ func AdjustValueToType(typ *types.T, inVal Datum) (outVal Datum, err error) { | |||
} else if _, ok := inVal.(*DCollatedString); ok { | |||
return NewDCollatedString(strings.TrimRight(sv, " "), typ.Locale(), &CollationEnvironment{}) | |||
} | |||
} else if typ.Oid() == oid.T_char { | |||
if _, ok := AsDString(inVal); ok { | |||
return NewDString(util.TruncateString(sv, 1)), nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we have to TruncateString again here?
i think we can omit the second usage of TrimRight above as well - oops.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you, good catch
pkg/sql/sem/tree/constant.go
Outdated
@@ -578,6 +584,11 @@ func (expr *StrVal) ResolveAsType( | |||
expr.resString = DString(strings.TrimRight(expr.s, " ")) | |||
return &expr.resString, nil | |||
} | |||
// "char" is supposed to truncate long values | |||
if typ.Oid() == oid.T_char { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this logic is very similar to above and the code in AdjustValueToType
.
Do you mind making a routine
func adjustStringToType(typ *types.T, str string) string {
switch typ.Oid() {
case oid.T_char:
// ...
case oid.T_bpchar:
// ...
}
return str
}
and using it in all three places, replacing the TrimRight && TruncateString code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
2fc0bc6
to
d143764
Compare
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 otan. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
bors r+
Build failed (retrying...): |
Build failed: |
d143764
to
8070c62
Compare
hmm seems like this is causing issues because of how we type CASE expressions (pkg/sql/opt/memo/typing.go):
so a CASE where the inputs are all cockroach/pkg/sql/delegate/show_table.go Lines 196 to 207 in 12eaa93
@otan any idea if it's safe to change that case typing rule? |
ah that's super gross :( we really should be asserting that all the i think for now the safest thing to do is change the CASE to |
Release note (sql change, backward-incompatible change): The "char" column type will truncate long values in line with Postgres.
8070c62
to
3309914
Compare
cockroach/pkg/sql/opt/memo/typing.go Lines 72 to 81 in 12eaa93
casting cockroach/pkg/sql/delegate/show_table.go Lines 202 to 208 in 3309914
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice. lgtm!
bors r+
Build succeeded: |
Resolves #65631
Release note (sql change, backward-incompatible change): The
"char"
column type will truncate long values in line with Postgres.