{"record":{"id":"37d9314e9f3dd806","repo":"jackc/pgx","slug":"cannot-scan-null-into-time-interval","errorCode":null,"errorMessage":"cannot scan NULL into *time.Interval","messagePattern":"cannot scan NULL into \\*time\\.Interval","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pgtype/builtin_wrappers.go","lineNumber":504,"sourceCode":"\treturn nil\n}\n\nfunc (w timeWrapper) TimeValue() (Time, error) {\n\tt := time.Time(w)\n\tusec := int64(t.Hour())*microsecondsPerHour +\n\t\tint64(t.Minute())*microsecondsPerMinute +\n\t\tint64(t.Second())*microsecondsPerSecond +\n\t\tint64(t.Nanosecond())/1000\n\treturn Time{Microseconds: usec, Valid: true}, nil\n}\n\ntype durationWrapper time.Duration\n\nfunc (w durationWrapper) SkipUnderlyingTypePlan() {}\n\nfunc (w *durationWrapper) ScanInterval(v Interval) error {\n\tif !v.Valid {\n\t\treturn fmt.Errorf(\"cannot scan NULL into *time.Interval\")\n\t}\n\n\tus := int64(v.Months)*microsecondsPerMonth + int64(v.Days)*microsecondsPerDay + v.Microseconds\n\t*w = durationWrapper(time.Duration(us) * time.Microsecond)\n\treturn nil\n}\n\nfunc (w durationWrapper) IntervalValue() (Interval, error) {\n\treturn Interval{Microseconds: int64(w) / 1000, Valid: true}, nil\n}\n\ntype netIPNetWrapper net.IPNet\n\nfunc (w *netIPNetWrapper) ScanNetipPrefix(v netip.Prefix) error {\n\tif !v.IsValid() {\n\t\treturn fmt.Errorf(\"cannot scan NULL into *net.IPNet\")\n\t}\n","sourceCodeStart":486,"sourceCodeEnd":522,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/pgtype/builtin_wrappers.go#L486-L522","documentation":"ScanInterval was given a NULL Interval while scanning into *time.Interval (a durationWrapper), which cannot represent NULL. Null guard in the interval-to-duration conversion; note the wrapper also flattens months/days into microseconds.","triggerScenarios":"Thrown at pgtype/builtin_wrappers.go:504 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use COALESCE with a zero interval default","Scan into pgtype.Interval or *time.Duration to handle NULLs","Ensure the column is NOT NULL"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"ec1a0befd22592cffffdeeb0a50311b506372f4c","analyzedAt":"2026-08-04T22:52:11.263Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}