You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am selecting rows from MySQL, and using MapScan() to scan data. The row data is BIGINT and VARCHAR, so I am expecting to get int64 and string (or []byte) data. But I got []uint8 for those data.
Here is the code:
package main
import (
"fmt"
"time"
_ "github.com/go-sql-driver/mysql"
"github.com/jmoiron/sqlx"
)
var DSN string = "user:pass@tcp(192.168.1.88:3306)/db?charset=utf8mb4"
func main() {
db, _ := sqlx.Open("mysql", DSN)
db.Exec(`DOP TABLE t`)
db.Exec(`CREATE TABLE t (
id INT,
name varchar(32)
)`)
db.Exec("INSERT INTO t (id, name) VALUES(?, ?)", time.Now().Unix(), "SomeName")
row := db.QueryRowx("SELECT * FROM t")
result := make(map[string]interface{})
row.MapScan(result)
fmt.Println(result)
}
The output is:
map[t.id:[49 54 52 52 57 57 57 50 49 54] t.name:[83 111 109 101 78 97 109 101]]
Data Type is: []uint8
Data Type is: []uint8
The name column is []uint8 data, ok that's acceptable, I can convert it to string manually.
But the data of the id column is wired, it is timestamp "1644999985" represented in ASCII code. I think this is not the correct behavior.
The text was updated successfully, but these errors were encountered:
I am selecting rows from MySQL, and using MapScan() to scan data. The row data is BIGINT and VARCHAR, so I am expecting to get int64 and string (or []byte) data. But I got []uint8 for those data.
Here is the code:
The output is:
The name column is []uint8 data, ok that's acceptable, I can convert it to string manually.
But the data of the id column is wired, it is timestamp "1644999985" represented in ASCII code. I think this is not the correct behavior.
The text was updated successfully, but these errors were encountered: