Standard library / database/sql

sql.NullInt32

Represents a potentially NULL database value; Valid distinguishes SQL NULL from a Go zero value. Expected stdout: 'true\nfalse\n'.

Formal Syntax & Structure

go syntaxgo
type NullInt32 struct {  Int32 int32  Valid bool}

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.NullInt32  check(n.Scan(int64(7)))  fmt.Println(n.Valid)  check(n.Scan(nil))  fmt.Println(n.Valid)}
Go Reference