jackc/pgx · error

cannot scan NULL into %T

Error message

cannot scan NULL into %T

What it means

Error "cannot scan NULL into %T" thrown in jackc/pgx.

Source

Thrown at pgtype/xml.go:165

}

type scanPlanXMLToXMLUnmarshal struct {
	unmarshal func(data []byte, v any) error
}

func (s *scanPlanXMLToXMLUnmarshal) 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, reflect.Struct:
				el.Set(reflect.Zero(el.Type()))
				return nil
			}
		}

		return fmt.Errorf("cannot scan NULL into %T", dst)
	}

	elem := reflect.ValueOf(dst).Elem()
	elem.Set(reflect.Zero(elem.Type()))

	return s.unmarshal(src, dst)
}

func (c *XMLCodec) 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)

When it happens

Trigger: Thrown at pgtype/xml.go:165 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/8e99e95cc4cf2797.json. Report an issue: GitHub.