jackc/pgx · error
is less than minimum value for int4
Error message
%d is less than minimum value for int4
What it means
Binary int4 encoding plan for Int64Valuer sources: the value is below math.MinInt32 and cannot be encoded as a 4-byte integer, so encoding aborts before writing.
Solutions
- Use an int8 parameter type for the value
- Validate/clamp the value to the int4 range before encoding
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at pgtype/int.go:759 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/7e6e886b4d9fdc1f.
Report an issue: GitHub.
Appendix: source
Thrown at pgtype/int.go:759
}
type encodePlanInt4CodecBinaryInt64Valuer struct{}
func (encodePlanInt4CodecBinaryInt64Valuer) Encode(value any, buf []byte) (newBuf []byte, err error) {
n, err := value.(Int64Valuer).Int64Value()
if err != nil {
return nil, err
}
if !n.Valid {
return nil, nil
}
if n.Int64 > math.MaxInt32 {
return nil, fmt.Errorf("%d is greater than maximum value for int4", n.Int64)
}
if n.Int64 < math.MinInt32 {
return nil, fmt.Errorf("%d is less than minimum value for int4", n.Int64)
}
return pgio.AppendInt32(buf, int32(n.Int64)), nil
}
type encodePlanInt4CodecTextInt64Valuer struct{}
func (encodePlanInt4CodecTextInt64Valuer) Encode(value any, buf []byte) (newBuf []byte, err error) {
n, err := value.(Int64Valuer).Int64Value()
if err != nil {
return nil, err
}
if !n.Valid {
return nil, nil
}
if n.Int64 > math.MaxInt32 {View on GitHub (pinned to ec1a0befd2)