您可以使用
pq.NullTime,或者在Go
1.13中,现在可以使用标准库的
sql.NullTime类型。
从github上的lib /
pq:
type NullTime struct { Time time.Time Valid bool // Valid is true if Time is not NULL}// Scan implements the Scanner interface.func (nt *NullTime) Scan(value interface{}) error { nt.Time, nt.Valid = value.(time.Time) return nil}// Value implements the driver Valuer interface.func (nt NullTime) Value() (driver.Value, error) { if !nt.Valid { return nil, nil } return nt.Time, nil}


