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

json_extract get wrong decimal when insert into table #12178

Closed
Tracked by #14541
wjhuang2016 opened this issue Sep 12, 2019 · 5 comments · Fixed by #21592
Closed
Tracked by #14541

json_extract get wrong decimal when insert into table #12178

wjhuang2016 opened this issue Sep 12, 2019 · 5 comments · Fixed by #21592
Assignees
Labels
component/expression component/json help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. severity/major sig/execution SIG execution type/bug The issue is confirmed as a bug.

Comments

@wjhuang2016
Copy link
Member

wjhuang2016 commented Sep 12, 2019

Description

Bug Report

Please answer these questions before submitting your issue. Thanks!

  1. What did you do?
    If possible, provide a recipe for reproducing the error.
create table ta(id decimal(60,2));
insert into ta values (JSON_EXTRACT('{"c": "1234567890123456789012345678901234567890123456789012345"}', '$.c'));
select * from ta;
  1. What did you expect to see?
mysql> select * from ta;
+------------------------------------------------------------+
| id                                                         |
+------------------------------------------------------------+
| 1234567890123456789012345678901234567890123456789012345.00 |
+------------------------------------------------------------+
1 row in set (0.00 sec)
  1. What did you see instead?
mysql> select * from ta;
+------------------------------------------------------------+
| id                                                         |
+------------------------------------------------------------+
| 1234567890123456800000000000000000000000000000000000000.00 |
+------------------------------------------------------------+
1 row in set (0.00 sec)
  1. What version of TiDB are you using (tidb-server -V or run select tidb_version(); on TiDB)?
mysql> select tidb_version();
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()                                                                                                                                                                                                                                                                                                                |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v4.0.0-alpha-177-gf9d85418e
Git Commit Hash: f9d85418ed13f54c02acfa0e97af32fb64f008e1
Git Branch: master
UTC Build Time: 2019-09-12 11:15:49
GoVersion: go version go1.12.4 linux/amd64
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

SIG slack channel

#sig-exec

Score

300

Mentor

@wjhuang2016 wjhuang2016 added the type/bug The issue is confirmed as a bug. label Sep 12, 2019
@Deardrops
Copy link
Contributor

Deardrops commented Nov 14, 2019

In TiDB:

mysql> select JSON_EXTRACT('{"c": "1234567890123456789012345678901234567890123456789012345"}', '$.c');
+-----------------------------------------------------------------------------------------+
| JSON_EXTRACT('{"c": "1234567890123456789012345678901234567890123456789012345"}', '$.c') |
+-----------------------------------------------------------------------------------------+
| "1234567890123456789012345678901234567890123456789012345"                               |
+-----------------------------------------------------------------------------------------+
1 row in set (0.01 sec)

mysql> select CAST(JSON_EXTRACT('{"c": "1234567890123456789012345678901234567890123456789012345"}', '$.c') as decimal(60,2));
+----------------------------------------------------------------------------------------------------------------+
| CAST(JSON_EXTRACT('{"c": "1234567890123456789012345678901234567890123456789012345"}', '$.c') as decimal(60,2)) |
+----------------------------------------------------------------------------------------------------------------+
|                                                     1234567890123456789012345678901234567890123456789012345.00 |
+----------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

and

mysql> create table ta(id decimal(60,2));
Query OK, 0 rows affected (0.01 sec)

mysql> insert into ta values (1234567890123456789012345678901234567890123456789012345.00);
Query OK, 1 row affected (0.01 sec)

mysql> select * from ta;
+------------------------------------------------------------+
| id                                                         |
+------------------------------------------------------------+
| 1234567890123456789012345678901234567890123456789012345.00 |
+------------------------------------------------------------+
1 row in set (0.00 sec)

@ghost
Copy link

ghost commented Jul 16, 2020

Confirming this issue still exists in master:

drop table if exists ta;
create table ta(id decimal(60,2));
insert into ta values (JSON_EXTRACT('{"c": "1234567890123456789012345678901234567890123456789012345"}', '$.c'));
select * from ta;

..

mysql> select * from ta;
+------------------------------------------------------------+
| id                                                         |
+------------------------------------------------------------+
| 1234567890123456800000000000000000000000000000000000000.00 |
+------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> select tidb_version()\G
*************************** 1. row ***************************
tidb_version(): Release Version: v4.0.0-beta.2-782-gb72e47e6d
Edition: Community
Git Commit Hash: b72e47e6db8863c08e47714391cf937b0f1c3269
Git Branch: master
UTC Build Time: 2020-07-15 01:26:06
GoVersion: go1.13
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
1 row in set (0.00 sec)

@ghost ghost added the component/json label Jul 25, 2020
@ghost ghost added the component/expression label Jul 25, 2020
@jebter jebter added the sig/execution SIG execution label Nov 11, 2020
@lzmhhh123 lzmhhh123 added challenge-program help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. labels Dec 4, 2020
@ichn-hu
Copy link
Contributor

ichn-hu commented Dec 9, 2020

/unlabel challenge-program

@ti-challenge-bot
Copy link

The issue has been removed from the challenge program.

@ti-srebot
Copy link
Contributor

Please edit this comment or add a new comment to complete the following information

Not a bug

  1. Remove the 'type/bug' label
  2. Add notes to indicate why it is not a bug

Duplicate bug

  1. Add the 'type/duplicate' label
  2. Add the link to the original bug

Bug

Note: Make Sure that 'component', and 'severity' labels are added
Example for how to fill out the template: #20100

1. Root Cause Analysis (RCA) (optional)

2. Symptom (optional)

3. All Trigger Conditions (optional)

4. Workaround (optional)

5. Affected versions

6. Fixed versions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/expression component/json help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. severity/major sig/execution SIG execution type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants