I am trying to map a table which looks like this:
Column | Type | Collation | Nullable | Default |
---|---|---|---|---|
time | timestamp without time zone | |||
NL | double precision |
to a struct like this:
type Price struct {
time time.Time `db:"time"`
NL float64 `db:"NL"`
}
with this code:
data := []Price{}
err = db.Select(&data, "" +
"SELECT \"time\",\"NL\" FROM <TABLENAME> where \"time\" > '2020-01-01' order by \"time\" desc")
if err != nil {
fmt.Println(err)
}
but I keep getting the error
missing destination name time in *[]main.Price
after some searching the fixes I applied in order of what I found (with above code as end result):
db:name
to the structThose were all the common solutions here on SO and other places on the internet. I dont understand why this doesnt work, can anybody help me? Thanks!
Reflection tools in Go only expose struct fields with Capitalized (exported) names.
Try changing time time.Time
to Time time.Time
.