JuliusBrussee/caveman · error
JSON number exceeds PostgreSQL fraction-digit limit
Error message
JSON number exceeds PostgreSQL fraction-digit limit
What it means
Error from normalizeJSONNumber: the number's fractional display scale (digits after the decimal point, adjusted by exponent) exceeds PostgreSQL numeric's limit. PostgreSQL retains input display scale in jsonb output — including trailing zeroes — so the raw scale is checked before canonical reduction strips zeroes.
Solutions
- Round or trim trailing fractional zeroes (and excess precision) before storing
- Re-express the value in scientific notation with fewer scale digits, or as a string
- Validate numeric scale at the ingestion boundary and reject with a domain message
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at shared/platform/proposalrun/proposalrun.go:231 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/bbc0c156fef0461f.
Report an issue: GitHub.
Appendix: source
Thrown at shared/platform/proposalrun/proposalrun.go:231
}
for i := 0; i < len(integerPart); i++ {
if integerPart[i] < '0' || integerPart[i] > '9' {
return "", fmt.Errorf("invalid JSON number")
}
}
for i := 0; i < len(fractionPart); i++ {
if fractionPart[i] < '0' || fractionPart[i] > '9' {
return "", fmt.Errorf("invalid JSON number")
}
}
// PostgreSQL numeric retains the input display scale in jsonb output,
// including trailing fractional zeroes. Validate the raw scale before the
// canonical reduction below strips those zeroes; otherwise a value such as
// 1.0000e-16383 would reduce to a representable scale while its original
// jsonb insert would fail at the 16383-digit numeric limit.
rawScale := len(fractionPart) - exponent
if rawScale > maxJSONBNumericFractionDigits {
return "", fmt.Errorf("JSON number exceeds PostgreSQL fraction-digit limit")
}
digits := strings.TrimLeft(integerPart+fractionPart, "0")
if digits == "" {
return "0", nil
}
scale := len(fractionPart) - exponent
for scale > 0 && strings.HasSuffix(digits, "0") {
digits = digits[:len(digits)-1]
scale--
}
var out string
switch {
case scale <= 0:
zeros := -scale
if zeros > maxJSONBNumericIntegerDigits-len(digits) {
return "", fmt.Errorf("JSON number exceeds PostgreSQL integer-digit limit")View on GitHub (pinned to 3ee70a1026)