jackc/pgx · error
cannot scan NULL into *string
Error message
cannot scan NULL into *string
What it means
Returned by stringWrapper.ScanText when the PostgreSQL text value is NULL (Valid==false). A plain Go string has no NULL representation, so the scan refuses rather than storing an empty string that would be indistinguishable from ''.
Solutions
- Use COALESCE(col, '') in the query when empty string is an acceptable default
- Scan into pgtype.Text or *string to preserve NULL semantics
- Declare the column NOT NULL
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at pgtype/builtin_wrappers.go:387 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/887a5d461e07af38.
Report an issue: GitHub.
Appendix: source
Thrown at pgtype/builtin_wrappers.go:387
return fmt.Errorf("cannot scan NULL into *float64")
}
*w = float64Wrapper(v.Float64)
return nil
}
func (w float64Wrapper) Float64Value() (Float8, error) {
return Float8{Float64: float64(w), Valid: true}, nil
}
type stringWrapper string
func (w stringWrapper) SkipUnderlyingTypePlan() {}
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 {View on GitHub (pinned to ec1a0befd2)