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

Fix cast int as decimal #7795

Closed
wants to merge 2 commits into from
Closed

Conversation

AndrewDi
Copy link
Contributor

What problem does this PR solve?

to fix #7778

What is changed and how it works?

change cast function init, if arg is unsigned, set cast function to unsigned, so that we can keep function return keep unsigned.

Check List

Tests

  • Unit test

Code changes

Side effects

Related changes

@sre-bot
Copy link
Contributor

sre-bot commented Sep 27, 2018

Hi contributor, thanks for your PR.

This patch needs to be approved by someone of admins. They should reply with "/ok-to-test" to accept this PR for running test automatically.

@zz-jason
Copy link
Member

@AndrewDi I'm sorry to inform you that I have to close this PR because the issue was fixed by #7792, and it was merged. Anyway, thanks for your great contribution!

@@ -227,6 +227,9 @@ func (c *castAsDecimalFunctionClass) getFunction(ctx sessionctx.Context, args []
} else {
argTp = args[0].GetType().EvalType()
}
if mysql.HasUnsignedFlag(args[0].GetType().Flag) {
Copy link
Member

Choose a reason for hiding this comment

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

The result flag doesn't contain the unsigned flag even if the input is an unsigned integer:

drop table if exists t;
create table t(a bigint unsigned);
insert into t values(pow(2, 63));

In MySQL

MySQL(localhost:3306) > select cast(a as decimal(65,0)) from t;
Field   1:  `cast(a as decimal(65,0))`
Catalog:    `def`
Database:   ``
Table:      ``
Org_table:  ``
Type:       NEWDECIMAL
Collation:  binary (63)
Length:     66
Max_length: 19
Decimals:   0
Flags:      BINARY NUM


+--------------------------+
| cast(a as decimal(65,0)) |
+--------------------------+
|      9223372036854775808 |
+--------------------------+
1 row in set (0.00 sec)

@zz-jason
Copy link
Member

@AndrewDi Feel free to reopen it. 😄

@zz-jason zz-jason closed this Sep 27, 2018
@AndrewDi AndrewDi deleted the fix_castIntAsDecimal branch September 27, 2018 11:14
@sre-bot sre-bot added the contribution This PR is from a community contributor. label Dec 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution This PR is from a community contributor.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cast(unsigned arg as decimal) doesn't work properly
3 participants