jackc/pgx · error
cannot scan NULL into *uint16
Error message
cannot scan NULL into *uint16
What it means
uint16Wrapper.ScanInt64 received an invalid (NULL) Int8 while the destination is a plain Go uint16, which cannot represent NULL.
Solutions
- Scan into *uint16 or a nullable type
- Filter NULLs in the query
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at pgtype/builtin_wrappers.go:159 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: /api/errors/8ea1b2982d5d4534.
Report an issue: GitHub.
Appendix: source
Thrown at pgtype/builtin_wrappers.go:159
if v.Int64 > math.MaxUint8 {
return fmt.Errorf("%d is greater than maximum value for uint8", v.Int64)
}
*w = uint8Wrapper(v.Int64)
return nil
}
func (w uint8Wrapper) Int64Value() (Int8, error) {
return Int8{Int64: int64(w), Valid: true}, nil
}
type uint16Wrapper uint16
func (w uint16Wrapper) SkipUnderlyingTypePlan() {}
func (w *uint16Wrapper) ScanInt64(v Int8) error {
if !v.Valid {
return fmt.Errorf("cannot scan NULL into *uint16")
}
if v.Int64 < 0 {
return fmt.Errorf("%d is less than minimum value for uint16", v.Int64)
}
if v.Int64 > math.MaxUint16 {
return fmt.Errorf("%d is greater than maximum value for uint16", v.Int64)
}
*w = uint16Wrapper(v.Int64)
return nil
}
func (w uint16Wrapper) Int64Value() (Int8, error) {
return Int8{Int64: int64(w), Valid: true}, nil
}
type uint32Wrapper uint32View on GitHub (pinned to ec1a0befd2)