jackc/pgx · error
unable to encode into OID in binary format
Error message
unable to encode %v into OID %d in binary format
What it means
Returned by the binary composite scan plan when Map.PlanScan returns nil for one of the composite's fields — no codec/plan exists to scan that field's OID in binary format into the chosen field target type.
Solutions
- Change the struct field's Go type to one the field's PostgreSQL type supports
- Register a custom codec for the field's OID in the TypeMap
- Scan the composite as text instead of binary
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at pgtype/composite.go:149 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/1036271ae639b4a2.
Report an issue: GitHub.
Appendix: source
Thrown at pgtype/composite.go:149
func (plan *scanPlanBinaryCompositeToCompositeIndexScanner) Scan(src []byte, target any) error {
targetScanner := (target).(CompositeIndexScanner)
if src == nil {
return targetScanner.ScanNull()
}
scanner := NewCompositeBinaryScanner(plan.m, src)
for i, field := range plan.cc.Fields {
if scanner.Next() {
fieldTarget, err := compositeFieldTarget(targetScanner, i)
if err != nil {
return err
}
if fieldTarget != nil {
fieldPlan := plan.m.PlanScan(field.Type.OID, BinaryFormatCode, fieldTarget)
if fieldPlan == nil {
return fmt.Errorf("unable to encode %v into OID %d in binary format", field, field.Type.OID)
}
err = fieldPlan.Scan(scanner.Bytes(), fieldTarget)
if err != nil {
return err
}
}
} else {
return errors.New("read past end of composite")
}
}
if err := scanner.Err(); err != nil {
return err
}
return nil
}View on GitHub (pinned to ec1a0befd2)