mysql - Selecting NULL Timestamps In Go With ziutek/mymysql -
i have following google go , mysql, date_update field in question comes null value.
var date_update time.time query := `select date_update users user_id=?` err := conn.queryrow(query, user_id).scan(&date_update) when run query , happen receive 1 of null values field, receive error unsupported driver -> scan pair: <nil> -> *time.time
the way handle other data types (for example int) with
select ifnull(integer_field, 0) table but doesn't seem work timestamps or datetime. ideas?
this google groups discussion discusses problem identical yours.
this section taken readme of go-sql-drivers/mysql repository.
time.time support
the default internal output type of mysql date , datetime values []byte allows scan value []byte, string or sql.rawbytes variable in programm.
however, many want scan mysql date , datetime values time.time variables, logical opposite in go date , datetime in mysql. can changing internal output type []byte time.time dsn parameter parsetime=true. can set default time.time location loc dsn parameter.
caution: of go 1.1, makes time.time variable type can scan date , datetime values into. breaks example sql.rawbytes support.
alternatively can use nulltime type scan destination, works both time.time , string / []byte.
you either have add parsetime=true dsn in order parse time.time automatically or use nulltime.
using mymysql
you try selecting row specific id & use 1 of following functions:
Comments
Post a Comment