Comments (7)
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.
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.
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.
@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.
https://github.com/jmoiron/sqlx/tree/slice-map-fix
from sqlx.
Great, thanks i will try that branch, if i run into bugs i will let you know.
from sqlx.
This has been integrated into master now, along with many other fixes.
from sqlx.
Related Issues (20)
- record and record[] fields coming back as text
- Is this project abandoned? HOT 9
- ConnectContext should close the db when PingContext returns an error
- I NEED YOUR HELP!!! query_as! UPDATE ... SET ...RETURNING...(unsupported type user_role for param #1) HOT 3
- [Question] Inverse of Get/Select? HOT 4
- missing destination name for field while it is not selected
- Behavioural differences between `sql.Named` with query vs `NamedExecContext` cause `UPDATE` error HOT 2
- how to call sqlite3_create_function_v2
- [Proposal] Replace the Test Host Level DB's with containers.
- Issue with mocking PrepareNamed
- Tag new version for dependency security updates HOT 1
- Batch insert still not working HOT 1
- Mysql "... update nowait" does not return error
- bindvar for MSSQL HOT 3
- Creating a connection pool with custom connector
- GetContext not in any interface -- propose adding interface GetterContext
- `Select()` mangling binary data when using `sql.RawBytes`
- issue with Bulk Insert in Planetscale: Argument Mismatch Error When Scaling Up HOT 1
- I've noticed that the GetContext method isn't part of any interface.I propose adding an interface, possibly named GetterContext, to address this issue. What are your thoughts? HOT 1
- error occurred
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sqlx.