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

cast int to decimal got wrong result when exceeds range #3920

Closed
guo-shaoge opened this issue Jan 20, 2022 · 1 comment · Fixed by #3922
Closed

cast int to decimal got wrong result when exceeds range #3920

guo-shaoge opened this issue Jan 20, 2022 · 1 comment · Fixed by #3922

Comments

@guo-shaoge
Copy link
Contributor

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

drop table if exists t1;
create table t1(c1 int);
insert into t1 values(9999);
alter table t1 set tiflash replica 1;
set tidb_enforce_mpp = 1;                                                                                                                                                                                                                                                                          set tidb_isolation_read_engines = 'tiflash';
select cast(c1 as decimal(4, 1)) from t1;

2. What did you expect to see? (Required)

MySQL [test]> select cast(c1 as decimal(4, 1)) from t1;
+---------------------------+
| cast(c1 as decimal(4, 1)) |
+---------------------------+
|                     999.9 |
+---------------------------+
1 row in set, 1 warning (0.00 sec)

3. What did you see instead (Required)

MySQL [test]> select cast(c1 as decimal(4, 1)) from t1;
+---------------------------+
| cast(c1 as decimal(4, 1)) |
+---------------------------+
|                    9999.0 |
+---------------------------+
1 row in set (0.02 sec)

4. What is your TiFlash version? (Required)

master

@fuzhe1989
Copy link
Contributor

In a word: when cast int as decimal, the overflow check ignores the scale and will accept some illegal data if scale > 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants