jackc/pgx · error

cannot scan composite field %d into CompositeFields of lengt

Error message

cannot scan composite field %d into CompositeFields of length %d

What it means

Error "cannot scan composite field %d into CompositeFields of length %d" thrown in jackc/pgx.

Source

Thrown at pgtype/composite.go:339

	cfs.fieldBytes, _ = cfs.r.Value()
	if err := cfs.r.Err(); err != nil {
		cfs.err = fmt.Errorf("Record incomplete: %w", err)
		return false
	}

	return true
}

func (cfs *CompositeBinaryScanner) FieldCount() int {
	return int(cfs.fieldCount)
}

// compositeFieldTarget returns the scan target for field i. CompositeFields is
// a slice, so indexing past its end would panic. A source with more fields than
// the destination is a mismatch that must be reported as an error.
func compositeFieldTarget(targetScanner CompositeIndexScanner, i int) (any, error) {
	if cf, ok := targetScanner.(CompositeFields); ok && i >= len(cf) {
		return nil, fmt.Errorf("cannot scan composite field %d into CompositeFields of length %d", i, len(cf))
	}

	return targetScanner.ScanIndex(i), nil
}

// Bytes returns the bytes of the field most recently read by Scan().
func (cfs *CompositeBinaryScanner) Bytes() []byte {
	return cfs.fieldBytes
}

// OID returns the OID of the field most recently read by Scan().
func (cfs *CompositeBinaryScanner) OID() uint32 {
	return cfs.fieldOID
}

// Err returns any error encountered by the scanner.
func (cfs *CompositeBinaryScanner) Err() error {
	return cfs.err

View on GitHub (pinned to ec1a0befd2)

When it happens

Trigger: Thrown at pgtype/composite.go:339 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/205945d94c1dcc43.json. Report an issue: GitHub.