jackc/pgx · error

cannot scan Infinity into *time.Time

Error message

cannot scan Infinity into *time.Time

What it means

ScanDate received a Date with InfinityModifier == Infinity, which time.Time cannot represent. PostgreSQL's infinite date was returned but the destination *time.Time only supports finite values; use pgtype.Date to handle infinity.

Solutions

  1. Scan into pgtype.Date, which supports InfinityModifier
  2. Filter or transform infinite values in the query (e.g. NULLIF/case expression)
  3. Constrain the column to finite dates
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pgtype/builtin_wrappers.go:410 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/74b8fb41c512d295. Report an issue: GitHub.

Appendix: source

Thrown at pgtype/builtin_wrappers.go:410

}

func (w stringWrapper) TextValue() (Text, error) {
	return Text{String: string(w), Valid: true}, nil
}

type timeWrapper time.Time

func (w *timeWrapper) ScanDate(v Date) error {
	if !v.Valid {
		return fmt.Errorf("cannot scan NULL into *time.Time")
	}

	switch v.InfinityModifier {
	case Finite:
		*w = timeWrapper(v.Time)
		return nil
	case Infinity:
		return fmt.Errorf("cannot scan Infinity into *time.Time")
	case NegativeInfinity:
		return fmt.Errorf("cannot scan -Infinity into *time.Time")
	default:
		return fmt.Errorf("invalid InfinityModifier: %v", v.InfinityModifier)
	}
}

func (w timeWrapper) DateValue() (Date, error) {
	return Date{Time: time.Time(w), Valid: true}, nil
}

func (w *timeWrapper) ScanTimestamp(v Timestamp) error {
	if !v.Valid {
		return fmt.Errorf("cannot scan NULL into *time.Time")
	}

	switch v.InfinityModifier {
	case Finite:

View on GitHub (pinned to ec1a0befd2)