{"id":"205945d94c1dcc43","repo":"jackc/pgx","slug":"cannot-scan-composite-field-d-into-compositefield","errorCode":null,"errorMessage":"cannot scan composite field %d into CompositeFields of length %d","messagePattern":"cannot scan composite field (.+?) into CompositeFields of length (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pgtype/composite.go","lineNumber":339,"sourceCode":"\tcfs.fieldBytes, _ = cfs.r.Value()\n\tif err := cfs.r.Err(); err != nil {\n\t\tcfs.err = fmt.Errorf(\"Record incomplete: %w\", err)\n\t\treturn false\n\t}\n\n\treturn true\n}\n\nfunc (cfs *CompositeBinaryScanner) FieldCount() int {\n\treturn int(cfs.fieldCount)\n}\n\n// compositeFieldTarget returns the scan target for field i. CompositeFields is\n// a slice, so indexing past its end would panic. A source with more fields than\n// the destination is a mismatch that must be reported as an error.\nfunc compositeFieldTarget(targetScanner CompositeIndexScanner, i int) (any, error) {\n\tif cf, ok := targetScanner.(CompositeFields); ok && i >= len(cf) {\n\t\treturn nil, fmt.Errorf(\"cannot scan composite field %d into CompositeFields of length %d\", i, len(cf))\n\t}\n\n\treturn targetScanner.ScanIndex(i), nil\n}\n\n// Bytes returns the bytes of the field most recently read by Scan().\nfunc (cfs *CompositeBinaryScanner) Bytes() []byte {\n\treturn cfs.fieldBytes\n}\n\n// OID returns the OID of the field most recently read by Scan().\nfunc (cfs *CompositeBinaryScanner) OID() uint32 {\n\treturn cfs.fieldOID\n}\n\n// Err returns any error encountered by the scanner.\nfunc (cfs *CompositeBinaryScanner) Err() error {\n\treturn cfs.err","sourceCodeStart":321,"sourceCodeEnd":357,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/pgtype/composite.go#L321-L357","documentation":"Error \"cannot scan composite field %d into CompositeFields of length %d\" thrown in jackc/pgx.","triggerScenarios":"Thrown at pgtype/composite.go:339 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"ec1a0befd22592cffffdeeb0a50311b506372f4c","analyzedAt":"2026-08-04T22:52:11.263Z","schemaVersion":2}