3 ms·
Does anyone else have the problem with nulls? It looks fairly simple, but inserts aren't mentioned here. From https://code.google.com/p/go-wiki/wiki/SQLInterf
by kristianp 13y ago
Does anyone else have the problem with nulls? It looks fairly simple, but inserts aren't mentioned here.
From https://code.google.com/p/go-wiki/wiki/SQLInterface https://code.google.com/p/go-wiki/wiki/SQLInterface
If a database column is nullable, one of the types supporting null values should
be passed to Scan.
For example, if the name column in the names table is nullable:
var name NullString
err := db.QueryRow(
"SELECT name FROM names WHERE id = ?", id).Scan(&name)
...
if name.Valid {
// use name.String
} else {
// value is NULL
}