Standard library / database/sql
sql.Null
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 Null[T any] struct { V T 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.Null[string] check(n.Scan("Ada")) fmt.Println(n.Valid) check(n.Scan(nil)) fmt.Println(n.Valid)}