0

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

Mukuro
  • 1
  • 1
    The comment in the tutorial is confusing. The values have the concrete type `sql.RawBytes`. There's no need to use type introspection to determine that. – Charlie Tumahai Jan 18 '19 at 06:47
  • Could this be relevant: https://stackoverflow.com/questions/29102725/go-sql-driver-get-interface-column-values? – Eli Bendersky Jan 18 '19 at 15:32

0 Answers0