jackc/pgx · error
invalid length for "char
Error message
invalid length for "char": %v
What it means
The "char" wire value is longer than one byte, but the type holds exactly one byte; the length check fires after NULL handling and rejects oversized payloads (only the empty/zero-byte case is permitted besides length 1).
Solutions
- Verify the column type is PostgreSQL "char" and not char(n) or text
- Check for data corruption or a codec mismatch on the wire format
- Use a Text or BPChar codec if variable-length character data is expected
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at pgtype/qchar.go:83 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/db524115efbb9aca.
Report an issue: GitHub.
Appendix: source
Thrown at pgtype/qchar.go:83
case *rune:
return scanPlanQcharCodecRune{}
case *string:
return scanPlanQcharCodecString{}
}
}
return nil
}
type scanPlanQcharCodecByte struct{}
func (scanPlanQcharCodecByte) Scan(src []byte, dst any) error {
if src == nil {
return fmt.Errorf("cannot scan NULL into %T", dst)
}
if len(src) > 1 {
return fmt.Errorf(`invalid length for "char": %v`, len(src))
}
b := dst.(*byte)
// In the text format the zero value is returned as a zero byte value instead of 0
if len(src) == 0 {
*b = 0
} else {
*b = src[0]
}
return nil
}
type scanPlanQcharCodecRune struct{}
func (scanPlanQcharCodecRune) Scan(src []byte, dst any) error {
if src == nil {
return fmt.Errorf("cannot scan NULL into %T", dst)View on GitHub (pinned to ec1a0befd2)