jackc/pgx · error

bad interval decimal format

Error message

bad interval decimal format: %s

What it means

Text interval parsing guard: the seconds fractional part after '.' failed strconv.ParseInt (non-numeric digits). The offending fraction substring is included in the message.

Solutions

  1. Use only digits after the decimal point in seconds
  2. Regenerate the interval text via PostgreSQL
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pgtype/interval.go:262 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/c0c54eb79528d297. Report an issue: GitHub.

Appendix: source

Thrown at pgtype/interval.go:262

		}

		minutes, err := strconv.ParseInt(timeParts[1], 10, 64)
		if err != nil {
			return fmt.Errorf("bad interval minute format: %s", timeParts[1])
		}

		sec, secFrac, secFracFound := strings.Cut(timeParts[2], ".")

		seconds, err := strconv.ParseInt(sec, 10, 64)
		if err != nil {
			return fmt.Errorf("bad interval second format: %s", sec)
		}

		var uSeconds int64
		if secFracFound {
			uSeconds, err = strconv.ParseInt(secFrac, 10, 64)
			if err != nil {
				return fmt.Errorf("bad interval decimal format: %s", secFrac)
			}

			for i := 0; i < 6-len(secFrac); i++ {
				uSeconds *= 10
			}
		}

		microseconds = hours * microsecondsPerHour
		microseconds += minutes * microsecondsPerMinute
		microseconds += seconds * microsecondsPerSecond
		microseconds += uSeconds

		if negative {
			microseconds = -microseconds
		}
	}

	return scanner.ScanInterval(Interval{Months: months, Days: days, Microseconds: microseconds, Valid: true})

View on GitHub (pinned to ec1a0befd2)