Code Monkey home page Code Monkey logo

Comments (7)

freeeve avatar freeeve commented on July 25, 2024 1

MapScan tries to scan everything out as a string. You should really be using a time.Time datatype to pull out timestamps--but if you want to do this with MapScan, you can convert to a string in the query with to_char or something.

from sqlx.

frankbb avatar frankbb commented on July 25, 2024 1

Do you have a suggestion for a workaround? Maybe you can also add this to the documentation for now.

In case of a SELECT * FROM A you don't know what type you are selecting so as far as i know there is no place for a to_char.

from sqlx.

jmoiron avatar jmoiron commented on July 25, 2024

Yes, this is a bug. The way lib/pq supports time natively, sql.RawBytes/[]byte/string/NullString aren't a safe destination for it. I have to change this code to use *interface{} instead, but that will probably be a breaking change. The way I did it wasn't good though; I learned this when writing the Unsafe() methods.

edit:

The map[string]*string interface is a lot more convenient than map[string]interface{} for most cases where MapScan is actually a good API, because you won't have a good idea of what the types are and a string representation is probably good enough. Still it's probably good enough to let fmt.Sprint do that work for you.

from sqlx.

jmoiron avatar jmoiron commented on July 25, 2024

@frankbb Fixing this is ironically a breaking change. I will create a branch for you to use which fixes this while I gather a bunch of planned breaking changes together for a single release + announcement.

Even though the current behavior is convenient, I think it is wrong. It's also unnecessarily opinionated to coerce everything to string or nil in the first place; if that's what someone desires, they could surely just fmt.Sprint the results for themselves.

from sqlx.

jmoiron avatar jmoiron commented on July 25, 2024

https://github.com/jmoiron/sqlx/tree/slice-map-fix

from sqlx.

frankbb avatar frankbb commented on July 25, 2024

Great, thanks i will try that branch, if i run into bugs i will let you know.

from sqlx.

jmoiron avatar jmoiron commented on July 25, 2024

This has been integrated into master now, along with many other fixes.

from sqlx.

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.