【发布时间】:2021-03-11 14:12:33
【问题描述】:
我创建了这样的表格:
CREATE TABLE MyTable
(
id uuid,
Test BOOLEAN NOT NULL,
end_date TIMESTAMP NULL DEFAULT NULL,
PRIMARY KEY (id)
);
我的结构
type Issue struct {
ID uuid.UUID
Test bool
EndDate time.Time `db:"due_date"`
}
现在的情况是,实时数据库中有一些日期没有EndDate,所以现在我在哪里查询以获取all data,我收到了这个错误
ERROR: sql: Scan error on column index 11, name "i.end_date": unsupported Scan, storing driver.Value type <nil> into type *time.Time
我不知道问题出在哪里。
更新
如果我使用 sql.NullTime 然后我做了一个这样的响应模式
return &model.Issue{
AssetOwnerID: id,
DueDate : time.Now().UTC().Truncate(time.Second)
}
我收到此错误
Cannot use 'time.Now().UTC().Truncate(time.Second)' (type Time) as type sql.NullTime
【问题讨论】:
标签: postgresql go grpc