jackc/pgx · error

cannot decode into Time

Error message

cannot decode %v into Time

What it means

The text time parser requires at least 8 bytes with ':' at positions 2 and 5 (HH:MM:SS shape); the input failed this structural check, so no numeric parsing is even attempted. The same message is reused for later numeric parse failures of the components.

Solutions

  1. Ensure the value matches PostgreSQL time output like "04:05:06.789"
  2. Normalize the time string (e.g. pad single-digit hours) before scanning
  3. Reject non-time strings before passing them to Scan
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pgtype/time.go:217 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/e453561620142fce. Report an issue: GitHub.

Appendix: source

Thrown at pgtype/time.go:217

		return err
	}

	return ts.ScanText(Text{String: string(buf), Valid: true})
}

type scanPlanTextAnyToTimeScanner struct{}

func (scanPlanTextAnyToTimeScanner) Scan(src []byte, dst any) error {
	scanner := (dst).(TimeScanner)

	if src == nil {
		return scanner.ScanTime(Time{})
	}

	s := string(src)

	if len(s) < 8 || s[2] != ':' || s[5] != ':' {
		return fmt.Errorf("cannot decode %v into Time", s)
	}

	hours, err := strconv.ParseInt(s[0:2], 10, 64)
	if err != nil {
		return fmt.Errorf("cannot decode %v into Time", s)
	}
	usec := hours * microsecondsPerHour

	minutes, err := strconv.ParseInt(s[3:5], 10, 64)
	if err != nil {
		return fmt.Errorf("cannot decode %v into Time", s)
	}
	usec += minutes * microsecondsPerMinute

	seconds, err := strconv.ParseInt(s[6:8], 10, 64)
	if err != nil {
		return fmt.Errorf("cannot decode %v into Time", s)
	}

View on GitHub (pinned to ec1a0befd2)