jackc/pgx · error
cannot unmarshal %s to timestamp with layout %s or %s (%w)
Error message
cannot unmarshal %s to timestamp with layout %s or %s (%w)
What it means
Error "cannot unmarshal %s to timestamp with layout %s or %s (%w)" thrown in jackc/pgx.
Source
Thrown at pgtype/timestamp.go:127
*ts = Timestamp{Valid: true, InfinityModifier: Infinity}
case "-infinity":
*ts = Timestamp{Valid: true, InfinityModifier: -Infinity}
default:
// Parse time with or without timezone
tss := *s
// PostgreSQL uses ISO 8601 without timezone for to_json function and casting from a string to timestamp
tim, err := time.Parse(time.RFC3339Nano, tss)
if err == nil {
*ts = Timestamp{Time: tim, Valid: true}
return nil
}
tim, err = time.ParseInLocation(jsonISO8601, tss, time.UTC)
if err == nil {
*ts = Timestamp{Time: tim, Valid: true}
return nil
}
ts.Valid = false
return fmt.Errorf("cannot unmarshal %s to timestamp with layout %s or %s (%w)",
*s, time.RFC3339Nano, jsonISO8601, err)
}
return nil
}
type TimestampCodec struct {
// ScanLocation is the location that the time is assumed to be in for scanning. This is different from
// TimestamptzCodec.ScanLocation in that this setting does change the instant in time that the timestamp represents.
ScanLocation *time.Location
}
func (*TimestampCodec) FormatSupported(format int16) bool {
return format == TextFormatCode || format == BinaryFormatCode
}
func (*TimestampCodec) PreferredFormat() int16 {
return BinaryFormatCode
}View on GitHub (pinned to ec1a0befd2)
When it happens
Trigger: Thrown at pgtype/timestamp.go:127 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: /data/errors/fe89da4b36f5fdb9.json.
Report an issue: GitHub.