V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
lalawac
V2EX  ›  问与答

go struct 里用什么类型来处理 mysql 的 decimal 类型的值

  •  
  •   lalawac · 2020-11-26 17:30:26 +08:00 · 1956 次点击
    这是一个创建于 1247 天前的主题,其中的信息可能已经有所发展或是发生改变。

    报错 Scan error on column index 4, name "money": converting driver.Value type []uint8 ("0.100") to a int: invalid syntax

    type Order struct{
    	Id    int     `"db:"id"`
    	Money float32 `"db:money"`
    }
     
    var order Order 
    rows, err = DB.Query("select money from order where id =1")
    rows.Scan(&order.Money)
    

    google 了半天,尝试了几种 decimal 类型仍然不行,

    第 1 条附言  ·  2020-11-26 18:06:51 +08:00
    我目前用的 database/sql 和 github.com/go-sql-driver/mysql , 参考用例的写的
    2 条回复    2020-11-26 18:17:44 +08:00
    rimutuyuan
        1
    rimutuyuan  
       2020-11-26 18:10:49 +08:00
    lalawac
        2
    lalawac  
    OP
       2020-11-26 18:17:44 +08:00
    @rimutuyuan 谢谢, 搞定了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   981 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 19:55 · PVG 03:55 · LAX 12:55 · JFK 15:55
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.