Golang 接入MySQL timestamp类型 是[]int8

表中有一个字段create_time, 在mysql中的类型是timestamp, 在go中对应的类型是 *time.Time. 在导出查询结果的时候, 遇到这样的报错

 sql: Scan error on column index 6: unsupported Scan, storing driver.Value type []uint8 into type *time.Time

看起来是驱动读取timestamp类型的数据时, 直接读取为int8的格式, 然后在尝试赋值到time.Time的时候出错了. 在Google后得到解决办法, 很简单, 直接在配置文件中的数据库连接地址最后加上parseTime=true的配置.

"addr": "test:passwd@tcp(127.0.0.1:3306)/test_database?charset=utf8&parseTime=true"

再看接收类型就是time.Time

猜你喜欢

转载自blog.csdn.net/happy_teemo/article/details/114002315
今日推荐