diff --git a/nulls.md b/nulls.md index 274b450..7f24082 100644 --- a/nulls.md +++ b/nulls.md @@ -53,6 +53,22 @@ for rows.Next() { } +Another trick to handle NULLs without using nullable types. + +Use pointers. + +
+for rows.Next() {
+	var s *string
+	err := rows.Scan(&s)
+	// check err
+	if s != nil {
+	   // use s.String
+	} else {
+	   // NULL value
+	}
+}
+
**Previous: [Handling Errors](errors.html)** **Next: [Working with Unknown Columns](varcols.html)**