-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Follow the SQL standard in cast from double or real to varchar #10657
Follow the SQL standard in cast from double or real to varchar #10657
Conversation
799ef4f
to
0572fa4
Compare
467e3cd
to
323ee7c
Compare
323ee7c
to
9359d9c
Compare
// String is all-ASCII, so String.length() here returns actual code points count | ||
if (stringValue.length() <= x) { | ||
return utf8Slice(stringValue); | ||
} | ||
|
||
throw new TrinoException(INVALID_CAST_ARGUMENT, format("Value %s cannot be represented as varchar(%s)", value, x)); | ||
throw new TrinoException(INVALID_CAST_ARGUMENT, format("Value %s cannot be represented as varchar(%s)", stringValue, x)); |
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.
provide original value
in the message, just in case we screw something up:
"Value %s (%s) ...", value, stringValue
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.
Applied to both double and real.
|
||
// handle positive and negative 0 | ||
if (value == 0e0) { | ||
if (1e0 / value > 0) { |
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.
or, arguably more directly, Double.compare(0.0, value) == 0
the Double.compare
sorts negative zero before positive zero
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.
I think it's clearer the way it is. Double.compare
would require a comment.
9359d9c
to
7bb9d8f
Compare
7bb9d8f
to
ce125d0
Compare
Related to #552