jackc/pgx · error

cannot scan %T

Error message

cannot scan %T

What it means

Thrown by UUID.Scan when database/sql delivers a value that is neither nil nor a string — the method only type-switches on string, so concrete types like []byte, int64, or time.Time fall through to this generic guard. The input at fault is the src value's Go type, not its contents.

Solutions

  1. Ensure the source column is UUID or text so the driver delivers a string
  2. Convert the value to a string before calling Scan
  3. Scan through pgx's native interface, which handles []byte sources, instead of database/sql
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at pgtype/uuid.go:88 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/d33dfbfbf096f2f1. Report an issue: GitHub.

Appendix: source

Thrown at pgtype/uuid.go:88

}

// Scan implements the [database/sql.Scanner] interface.
func (dst *UUID) Scan(src any) error {
	if src == nil {
		*dst = UUID{}
		return nil
	}

	if src, ok := src.(string); ok {
		buf, err := parseUUID(src)
		if err != nil {
			return err
		}
		*dst = UUID{Bytes: buf, Valid: true}
		return nil
	}

	return fmt.Errorf("cannot scan %T", src)
}

// Value implements the [database/sql/driver.Valuer] interface.
func (src UUID) Value() (driver.Value, error) {
	if !src.Valid {
		return nil, nil
	}

	return encodeUUID(src.Bytes), nil
}

func (src UUID) String() string {
	if !src.Valid {
		return ""
	}

	return encodeUUID(src.Bytes)
}

View on GitHub (pinned to ec1a0befd2)