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)
    

      

  • 相关阅读:
    spring Pom jar包版本管理
    Liunx 命令整理
    Centos&Nginx
    docker-compose
    .net core MemoryCache缓存
    .net core 程序集帮助类
    .NET CORE API Swagger
    Spring Boot (1)
    SQL Server生成实体
    1、认识和安装MongoDB
  • 原文地址:https://www.cnblogs.com/milton/p/9976881.html
Copyright © 2011-2022 走看看