Go: Working effectively with database nulls

This post covers how to marshall null values from a database into a Go struct type and how to save nulls back to the database. I’ll cover the standard library’s sql.NullString, NullInt64, NullFloat64, etc types — which I’ll refer to as sql.NullXYZ when indicating the collection of types and not a specific Null type — important methods on those types, telltale errors, and some helpers for working with values coming from form posts. This code uses SQL and the standard library. Takeaways In structs, use sql.NullString, sql.NullInt64, and its ilk instead of string and int for fields that persist to … Continue reading Go: Working effectively with database nulls