In Go database/sql tutorial. It said when Working with Unknown Columns, we should use sql.RawBytes. And the demo is after:
cols, err := rows.Columns() // Remember to check err afterwards
vals := make([]interface{}, len(cols))
for i, _ := range cols {
vals[i] = new(sql.RawBytes)
}
for rows.Next() {
err = rows.Scan(vals...)
// Now you can check each element of vals for nil-ness,
// and you can use type introspection and type assertions
// to fetch the column into a typed variable.
}
The last three lines said:
Now you can check each element of vals for nil-ness, and you can use type introspection and type assertions to fetch the column into a typed variable.
What I want to know is 【HOW TO use type introspection and type assertions to fetch the column into a typed variable】