jackc/pgx · error
microseconds cannot be represented as time.Time
Error message
%d microseconds cannot be represented as time.Time
What it means
Returned by timeWrapper.ScanTime when the PostgreSQL time-of-day exceeds 23:59:59.999999 microseconds. PostgreSQL allows 24:00:00, but Go's time.Time would normalize it to midnight of the next day, silently changing the value, so it is rejected instead.
Solutions
- Scan into pgtype.Time, which stores raw microseconds and supports 24:00:00
- Handle the 24:00:00 case explicitly before converting to time.Time
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at pgtype/builtin_wrappers.go:474 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/d2a046b565cc3b70.
Report an issue: GitHub.
Appendix: source
Thrown at pgtype/builtin_wrappers.go:474
return fmt.Errorf("cannot scan -Infinity into *time.Time")
default:
return fmt.Errorf("invalid InfinityModifier: %v", v.InfinityModifier)
}
}
func (w timeWrapper) TimestamptzValue() (Timestamptz, error) {
return Timestamptz{Time: time.Time(w), Valid: true}, nil
}
func (w *timeWrapper) ScanTime(v Time) error {
if !v.Valid {
return fmt.Errorf("cannot scan NULL into *time.Time")
}
// 24:00:00 is max allowed time in PostgreSQL, but time.Time will normalize that to 00:00:00 the next day.
var maxRepresentableByTime int64 = 24*60*60*1000000 - 1
if v.Microseconds > maxRepresentableByTime {
return fmt.Errorf("%d microseconds cannot be represented as time.Time", v.Microseconds)
}
usec := v.Microseconds
hours := usec / microsecondsPerHour
usec -= hours * microsecondsPerHour
minutes := usec / microsecondsPerMinute
usec -= minutes * microsecondsPerMinute
seconds := usec / microsecondsPerSecond
usec -= seconds * microsecondsPerSecond
ns := usec * 1000
*w = timeWrapper(time.Date(2000, 1, 1, int(hours), int(minutes), int(seconds), int(ns), time.UTC))
return nil
}
func (w timeWrapper) TimeValue() (Time, error) {
t := time.Time(w)
usec := int64(t.Hour())*microsecondsPerHour +
int64(t.Minute())*microsecondsPerMinute +View on GitHub (pinned to ec1a0befd2)