zoukankan      html  css  js  c++  java
  • MySQL5.7在JSON解析后丢失小数部分的Bug

    在MySQL Bugs上提交了 https://bugs.mysql.com/bug.php?id=84935 . 已经在MySQL8.0.1中修复

    重现步骤

    -- Prepare the table and populate it with records
    
    CREATE TABLE `voucher` (
      `id` varchar(32) NOT NULL COMMENT 'ID',
      `vals` mediumtext NOT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    
    INSERT INTO `voucher` VALUES ('1', '{"period":90,"amount":5.45}');
    INSERT INTO `voucher` VALUES ('2', '{"period":90,"amount":3.99}');
    
    -- Execute queries
    
    mysql> SELECT vals FROM voucher WHERE id='1';
    +-----------------------------+
    | vals                        |
    +-----------------------------+
    | {"period":90,"amount":5.45} |
    +-----------------------------+
    1 row in set (0.00 sec)
    
    mysql> SELECT json_extract(vals, '$.amount') FROM voucher WHERE id='1';
    +--------------------------------+
    | json_extract(vals, '$.amount') |
    +--------------------------------+
    | 5.45                           |
    +--------------------------------+
    1 row in set (0.00 sec)
    
    -- The result of this one is not correct
    mysql> SELECT SUM(json_extract(vals, '$.amount')) FROM voucher WHERE id='1'; 
    +-------------------------------------+
    | SUM(json_extract(vals, '$.amount')) |
    +-------------------------------------+
    |                                   5 |
    +-------------------------------------+
    1 row in set (0.00 sec)
    
    mysql> SELECT ROUND(SUM(json_extract(vals, '$.amount')), 2) FROM voucher WHERE id='1';
    +-----------------------------------------------+
    | ROUND(SUM(json_extract(vals, '$.amount')), 2) |
    +-----------------------------------------------+
    |                                          5.45 |
    +-----------------------------------------------+
    1 row in set (0.00 sec)
    

      

  • 相关阅读:
    CodeForces 1332D Walk on Matrix
    CodeForces 1324F Maximum White Subtree
    CodeForces-1324E-Sleeping-Schedule
    CodeForces-1324D-Pair-of-Topics
    理解字节序 大端字节序和小端字节序
    公钥 私钥 数字证书概念理解
    简要介绍 X Window System (又称为X11 or X)
    动态规划的简洁说明
    二分法的研究
    两个变量的内容交换
  • 原文地址:https://www.cnblogs.com/milton/p/9976881.html
Copyright © 2011-2022 走看看