How to dynamically fetch columns from database without a predefined struct?
values := make([]interface{}, 5)
for i := range values {
values[i] = new(interface{})
}
err = db.QueryRow(`SELECT id, block_id, account_id_, type, name FROM .account WHERE id=?`, id).Scan(values...)
if err != nil {
fmt.Println("err:", err)
}
for i := range values {
fmt.Println(values[i])
//fmt.Println(*values[i]) <---- this will result in compile error
}
When printing out the scanned variables a pointer is returned. If I try to dereference it *values[i]
a compile error is returned?
Output looks something like this
0xc0000331e0
0xc0000331f0
0xc000033200
0xc000033210
0xc000033220
New contributor
simme is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
4