jackc/pgx · error

cannot convert to sql.Scanner: cannot find registered type…

Error message

cannot convert to sql.Scanner: cannot find registered type for %T

What it means

sqlScannerWrapper adapts an arbitrary Go value into a database/sql.Scanner by looking up the value's registered PostgreSQL type in the Map. This guard fires when TypeForValue finds no registration for the value's Go type — RegisterDefaultPgType was never called for it, so there is no OID to decode the incoming bytes as.

Solutions

  1. Call RegisterDefaultPgType on the Map with the Go type and its PostgreSQL OID before scanning
  2. Scan into a concrete type instead of relying on SQLScanner wrapping
  3. Use pgtype's native scan path rather than the database/sql adapter
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at pgtype/pgtype.go:2022 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/96abbd0cd90ba106. Report an issue: GitHub.

Appendix: source

Thrown at pgtype/pgtype.go:2022

// This uses the type of v to look up the PostgreSQL OID that v presumably came from. This means v must be registered
// with m by calling RegisterDefaultPgType.
func (m *Map) SQLScanner(v any) sql.Scanner {
	if s, ok := v.(sql.Scanner); ok {
		return s
	}

	return &sqlScannerWrapper{m: m, v: v}
}

type sqlScannerWrapper struct {
	m *Map
	v any
}

func (w *sqlScannerWrapper) Scan(src any) error {
	t, ok := w.m.TypeForValue(w.v)
	if !ok {
		return fmt.Errorf("cannot convert to sql.Scanner: cannot find registered type for %T", w.v)
	}

	var bufSrc []byte
	if src != nil {
		switch src := src.(type) {
		case string:
			bufSrc = []byte(src)
		case []byte:
			bufSrc = src
		default:
			bufSrc = fmt.Append(nil, bufSrc)
		}
	}

	return w.m.Scan(t.OID, TextFormatCode, bufSrc, w.v)
}

var valuerReflectType = reflect.TypeFor[driver.Valuer]()

View on GitHub (pinned to ec1a0befd2)