Standard library / database/sql

sql.NullString.Scan()

Converts a driver value into the nullable wrapper. Nil marks it invalid; check the conversion error before using it. Expected stdout: 'true\nfalse\n'.

Formal Syntax & Structure

go syntaxgo
func (ns *NullString) Scan(value any) error

Parameters & Attributes

NameTypeDescription
valueanyValue to convert or scan; nil represents SQL NULL.

Return Value

error

Converts a driver value into the nullable wrapper. Check returned errors where applicable.

Working Example

Example Snippetgo
package main
import (  "database/sql"  "fmt")
func must[T any](v T, e error) T {  if e != nil {    panic(e)  }  return v}func check(e error) {  if e != nil {    panic(e)  }}func main() {  var n sql.NullString  check(n.Scan("Ada"))  fmt.Println(n.Valid)  check(n.Scan(nil))  fmt.Println(n.Valid)}
Go Reference