echotpq
V2EX  ›  问与答

mysql8 执行 update 后 多了小数点,求解

  •  
  •   echotpq · Nov 23, 2018 · 1496 views
    This topic created in 2749 days ago, the information mentioned may be changed or developed.

    1: 数据库 mysql8 ; json 字段 info {"a":1,"b":2}

    2:update mytable set info=json_set(info,'$."a"',info->'$."a"'+1) where id= 111;

    3: 执行 update 后的 info {"a":2.0,"b":2}

    竟然多了小数点,求教解决方法

    2 replies    2018-11-23 17:11:30 +08:00
    msg7086
        1
    msg7086  
       Nov 23, 2018
    随便帮你查了一下。JSON 并没有整数与小数之分,所以 2 和 2.0 在 JSON 里是等价的。
    SingeeKing
        2
    SingeeKing  
    PRO
       Nov 23, 2018
    https://tools.ietf.org/html/rfc7159#section-6

    number = [ minus ] int [ frac ] [ exp ]

    并不区分整数和浮点数
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3124 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 00:22 · PVG 08:22 · LAX 17:22 · JFK 20:22
    ♥ Do have faith in what you're doing.