jackc/pgx · error

read past end of composite

Error message

read past end of composite

What it means

Composite-type scan guard: the registered composite type declares more fields than the binary representation being decoded contains — the field scanner ran out of bytes before all planned fields were read. The mismatch is between the composite type registered on the Go side and the data sent by the server (usually a stale registration after an ALTER TYPE).

Solutions

  1. Re-register the composite type so its field list matches the server's current definition
  2. Verify the column really holds the expected composite type
  3. Check that null fields are represented per the binary composite format
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pgtype/composite.go:158 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/c249841c7de37e01. Report an issue: GitHub.

Appendix: source

Thrown at pgtype/composite.go:158

	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
}

type scanPlanTextCompositeToCompositeIndexScanner struct {
	cc *CompositeCodec
	m  *Map
}

func (plan *scanPlanTextCompositeToCompositeIndexScanner) Scan(src []byte, target any) error {
	targetScanner := (target).(CompositeIndexScanner)

View on GitHub (pinned to ec1a0befd2)