jackc/pgx · error

cannot scan NULL into *net.IPNet

Error message

cannot scan NULL into *net.IPNet

What it means

Error "cannot scan NULL into *net.IPNet" thrown in jackc/pgx.

Source

Thrown at pgtype/builtin_wrappers.go:520

func (w *durationWrapper) ScanInterval(v Interval) error {
	if !v.Valid {
		return fmt.Errorf("cannot scan NULL into *time.Interval")
	}

	us := int64(v.Months)*microsecondsPerMonth + int64(v.Days)*microsecondsPerDay + v.Microseconds
	*w = durationWrapper(time.Duration(us) * time.Microsecond)
	return nil
}

func (w durationWrapper) IntervalValue() (Interval, error) {
	return Interval{Microseconds: int64(w) / 1000, Valid: true}, nil
}

type netIPNetWrapper net.IPNet

func (w *netIPNetWrapper) ScanNetipPrefix(v netip.Prefix) error {
	if !v.IsValid() {
		return fmt.Errorf("cannot scan NULL into *net.IPNet")
	}

	*w = netIPNetWrapper{
		IP:   v.Addr().AsSlice(),
		Mask: net.CIDRMask(v.Bits(), v.Addr().BitLen()),
	}

	return nil
}

func (w netIPNetWrapper) NetipPrefixValue() (netip.Prefix, error) {
	ip, ok := netip.AddrFromSlice(w.IP)
	if !ok {
		return netip.Prefix{}, errors.New("invalid net.IPNet")
	}

	ones, _ := w.Mask.Size()

View on GitHub (pinned to ec1a0befd2)

When it happens

Trigger: Thrown at pgtype/builtin_wrappers.go:520 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of jackc/pgx@ec1a0befd2 (2026-08-04). Data as JSON: /data/errors/52aaa6e87fba2f04.json. Report an issue: GitHub.