Sqlx: Error is: sql: Scan error on column index 39: unsupported driver -> Scan pair: <nil> -> *time.Time

Created on 12 Jan 2016  路  6Comments  路  Source: jmoiron/sqlx

So I'm using sqlx and I have this error:

Error is: sql: Scan error on column index 39: unsupported driver -> Scan pair: -> *time.Time

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 ?

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.

All 6 comments

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.

@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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wyattjoh picture wyattjoh  路  4Comments

webRat picture webRat  路  4Comments

resal81 picture resal81  路  5Comments

MichaelHipp picture MichaelHipp  路  5Comments

pt-arvind picture pt-arvind  路  4Comments