{"record":{"id":"a8b3d584cfe7c61f","repo":"jackc/pgx","slug":"v-cannot-be-encoded-to-char","errorCode":null,"errorMessage":"%v cannot be encoded to \"char\"","messagePattern":"(.+?) cannot be encoded to \"char\"","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pgtype/qchar.go","lineNumber":52,"sourceCode":"\t}\n\n\treturn nil\n}\n\ntype encodePlanQcharCodecByte struct{}\n\nfunc (encodePlanQcharCodecByte) Encode(value any, buf []byte) (newBuf []byte, err error) {\n\tb := value.(byte)\n\tbuf = append(buf, b)\n\treturn buf, nil\n}\n\ntype encodePlanQcharCodecRune struct{}\n\nfunc (encodePlanQcharCodecRune) Encode(value any, buf []byte) (newBuf []byte, err error) {\n\tr := value.(rune)\n\tif r > math.MaxUint8 {\n\t\treturn nil, fmt.Errorf(`%v cannot be encoded to \"char\"`, r)\n\t}\n\tb := byte(r)\n\tbuf = append(buf, b)\n\treturn buf, nil\n}\n\nfunc (QCharCodec) PlanScan(m *Map, oid uint32, format int16, target any) ScanPlan {\n\tswitch format {\n\tcase TextFormatCode, BinaryFormatCode:\n\t\tswitch target.(type) {\n\t\tcase *byte:\n\t\t\treturn scanPlanQcharCodecByte{}\n\t\tcase *rune:\n\t\t\treturn scanPlanQcharCodecRune{}\n\t\tcase *string:\n\t\t\treturn scanPlanQcharCodecString{}\n\t\t}\n\t}","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/pgtype/qchar.go#L34-L70","documentation":"Encoding a rune into PostgreSQL's single-byte \"char\" type fails when the rune's value exceeds 255, since \"char\" holds exactly one byte. This is an out-of-range check on the Go-side value before it is appended to the buffer.","triggerScenarios":"Thrown at pgtype/qchar.go:52 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Clamp or validate the rune to the 0-255 range before encoding","Use a text type instead of \"char\" if multi-byte characters must be stored","Map unsupported runes to a sentinel byte value explicitly"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"ec1a0befd22592cffffdeeb0a50311b506372f4c","analyzedAt":"2026-08-04T22:52:11.263Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}