Giter VIP home page Giter VIP logo

Comments (4)

caibirdme avatar caibirdme commented on July 4, 2024

没太看懂你的问题,要不你贴一段代码,注释上你期望的结果和实际结果

from gendry.

MandssS avatar MandssS commented on July 4, 2024

eg: id user_name 字段的定义在最上面
1 nan
select user_name from a where id = 1;
我希望得到的 string(nan)
但是我最后得到的是float64(NaN)

from gendry.

caibirdme avatar caibirdme commented on July 4, 2024

了解了,这个是因为 strconv这里做了特殊处理

我看你里面有会先将string转为[110 97 110]uint8,然后再转出float64(NaN)。想问下,当初你们这样设计是出于什么考虑呢

并没有将string转成[]uint8,而是go-sql-driver/mysql这个驱动返回的数据类型就是[]uint8,这里只是类型推断,不是类型转换。由于历史原因,驱动的不同版本对同一个mysql的数据类型可能返回不同的值,在某些版本bigint会使用[]byte来返回,因此这里需要类型推断到[]uint8(等价于[]byte),然后尝试进行类型转换。

目前看起来你面临的问题暂时是无法解决的,如果驱动不能保证所有数值类型从rows里读出来都是数值类型,那这里就得做这么一层转换。

解决方案是,你可以换成Scan方法,定义一个结构体,这样在进行类型转换时会按照你期望的类型来转换

from gendry.

caibirdme avatar caibirdme commented on July 4, 2024

If no more questions, I will close the issue

from gendry.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.