jackc/pgx · error
cannot scan NULL into *time.Time
Error message
cannot scan NULL into *time.Time
What it means
ScanDate was given a NULL Date while scanning into *time.Time, which has no NULL representation. Null guard in timeWrapper; the date column is NULL but the destination is a plain time.Time rather than pgtype.Date or a nullable wrapper.
Solutions
- Use COALESCE with a sentinel date in the query
- Scan into pgtype.Date or *time.Time to handle NULLs
- Ensure the column is NOT NULL
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at pgtype/builtin_wrappers.go:402 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/11e345990e47b314.
Report an issue: GitHub.
Appendix: source
Thrown at pgtype/builtin_wrappers.go:402
func (w *stringWrapper) ScanText(v Text) error {
if !v.Valid {
return fmt.Errorf("cannot scan NULL into *string")
}
*w = stringWrapper(v.String)
return nil
}
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
}View on GitHub (pinned to ec1a0befd2)