jackc/pgx · error
invalid length for ReadyForQuery.TxStatus
Error message
invalid length for ReadyForQuery.TxStatus
What it means
ReadyForQuery.UnmarshalJSON guard: the JSON representation's TxStatus field does not have exactly one character. The PostgreSQL wire protocol defines ReadyForQuery's transaction status as a single byte ('I', 'T', or 'E'), so any other length cannot be mapped; the malformed JSON field is the faulty input.
Solutions
- Supply TxStatus as exactly one of "I", "T", or "E"
- Fix the JSON generator that produced the multi-character status
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at pgproto3/ready_for_query.go:57 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/c0d46a8090b3a21d.
Report an issue: GitHub.
Appendix: source
Thrown at pgproto3/ready_for_query.go:57
TxStatus: string(src.TxStatus),
})
}
// UnmarshalJSON implements encoding/json.Unmarshaler.
func (dst *ReadyForQuery) UnmarshalJSON(data []byte) error {
// Ignore null, like in the main JSON package.
if string(data) == "null" {
return nil
}
var msg struct {
TxStatus string
}
if err := json.Unmarshal(data, &msg); err != nil {
return err
}
if len(msg.TxStatus) != 1 {
return errors.New("invalid length for ReadyForQuery.TxStatus")
}
dst.TxStatus = msg.TxStatus[0]
return nil
}
View on GitHub (pinned to ec1a0befd2)