So I'm using sqlx and I have this error:
Error is: sql: Scan error on column index 39: unsupported driver -> Scan pair:
My structure looks like this:
type Person struct {
ID int64 `db:"id"`
Name string `db:"name"`
Surname string `db:"surname"`
BirthSurname string `db:"birthsurname"`
Nicknames string `db:"nicknames"`
DOB time.Time `db:"dob"`
}
and I connect to mysql db like this:
db, err = sqlx.Connect("mysql", "root@tcp(192.168.40.30:3306)/db?charset=utf8&parseTime=true")
I didn't find similar issues for sqlx package only for sql package, so I'm asking here what should be workaround for this ?
Can you show me the schema for your database and the Go code for your query as well?
Hi jmoiron, sure...
My schema looks like this:
CREATE TABLE person (
id int(11) NOT NULL AUTO_INCREMENT,
name varchar(45) DEFAULT NULL,
surname varchar(45) DEFAULT NULL,
birthsurname varchar(45) DEFAULT NULL,
nicknames varchar(300) DEFAULT NULL,
dob datetime DEFAULT NULL
) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=latin1;
And go query:
var db *sqlx.DB
err = db.Get(&girl, "SELECT * FROM person WHERE id=?", id) //id is valid.
I'm receiving this error as well. However, my db schema uses timestamp NULL and my Go struct is time.Time. I should note that I use postgres.
If you use postgres, you can get around it by using https://github.com/lib/pq/blob/b269bd035a727d6c1081f76e7a239a1b00674c40/encode.go#L521
@jmoiron is there an idiomatic way to use time.Time with sql?
Using *time.Time feels ugly.
Using NullTime struct is even uglier.
You should be able to create your own type that embeds *time.Time and implements Scan/Value.
Most helpful comment
@jmoiron is there an idiomatic way to use time.Time with sql?
Using *time.Time feels ugly.
Using NullTime struct is even uglier.