How do I handle NULL values using pgx?

NULL values, pgx, Golang, PostgreSQL handling, database management
This example demonstrates how to handle NULL values using the pgx library in Golang for PostgreSQL.
package main

import (
    "database/sql"
    "fmt"
    "log"

    "github.com/jackc/pgx/v4"
    "golang.org/x/net/context"
)

func main() {
    conn, err := pgx.Connect(context.Background(), "postgres://username:password@localhost:5432/mydb")
    if err != nil {
        log.Fatal(err)
    }
    defer conn.Close(context.Background())

    var name sql.NullString
    err = conn.QueryRow(context.Background(), "SELECT name FROM users WHERE id=$1", 1).Scan(&name)
    if err != nil {
        log.Fatal(err)
    }

    if name.Valid {
        fmt.Printf("Name: %s\n", name.String)
    } else {
        fmt.Println("Name is NULL")
    }
}
    

NULL values pgx Golang PostgreSQL handling database management