Skip to content
This repository has been archived by the owner on May 24, 2023. It is now read-only.

Add a trick to handle null sql query results #91

Open
wants to merge 1 commit into
base: gh-pages
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions nulls.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ for rows.Next() {
}
</pre>

Another trick to handle NULLs without using nullable types.

Use pointers.

<pre class="prettyprint lang-go">
for rows.Next() {
var s *string
err := rows.Scan(&amp;s)
// check err
if s != nil {
// use s.String
} else {
// NULL value
}
}
</pre>

**Previous: [Handling Errors](errors.html)**
**Next: [Working with Unknown Columns](varcols.html)**