jackc/pgx · error
cannot scan into non-pointer or nil destinations %T
Error message
cannot scan into non-pointer or nil destinations %T
What it means
This guard in the JSONUnmarshal scan plan verifies that the destination passed to Scan is a non-nil Go pointer before reflection is used to set it. It fires when dst is not a pointer at all, or is a nil pointer, making assignment impossible; the offending destination type is included in the message.
Solutions
- Always pass the address of the target variable (e.g. &myValue) to Scan
- Ensure the destination pointer is initialized and non-nil before scanning
- Check the variable declaration for a missing & operator
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at pgtype/json.go:216 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/39f64572b26566f4.
Report an issue: GitHub.
Appendix: source
Thrown at pgtype/json.go:216
func (s *scanPlanJSONToJSONUnmarshal) Scan(src []byte, dst any) error {
if src == nil {
dstValue := reflect.ValueOf(dst)
if dstValue.Kind() == reflect.Pointer {
el := dstValue.Elem()
switch el.Kind() {
case reflect.Pointer, reflect.Slice, reflect.Map, reflect.Interface:
el.Set(reflect.Zero(el.Type()))
return nil
}
}
return fmt.Errorf("cannot scan NULL into %T", dst)
}
v := reflect.ValueOf(dst)
if v.Kind() != reflect.Pointer || v.IsNil() {
return fmt.Errorf("cannot scan into non-pointer or nil destinations %T", dst)
}
elem := v.Elem()
elem.Set(reflect.Zero(elem.Type()))
return s.unmarshal(src, dst)
}
func (c *JSONCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error) {
if src == nil {
return nil, nil
}
dstBuf := make([]byte, len(src))
copy(dstBuf, src)
return dstBuf, nil
}
View on GitHub (pinned to ec1a0befd2)