{"record":{"id":"cec5b3f76ecf35e9","repo":"jackc/pgx","slug":"cannot-scan-null-into-uint","errorCode":null,"errorMessage":"cannot scan NULL into *uint","messagePattern":"cannot scan NULL into \\*uint","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pgtype/builtin_wrappers.go","lineNumber":282,"sourceCode":"\t\treturn fmt.Errorf(\"%d is greater than maximum value for uint\", v.Int64)\n\t}\n\n\t*w = uintWrapper(v.Int64)\n\n\treturn nil\n}\n\nfunc (w uintWrapper) Int64Value() (Int8, error) {\n\tif uint64(w) > uint64(math.MaxInt64) {\n\t\treturn Int8{}, fmt.Errorf(\"%d is greater than maximum value for int64\", w)\n\t}\n\n\treturn Int8{Int64: int64(w), Valid: true}, nil\n}\n\nfunc (w *uintWrapper) ScanNumeric(v Numeric) error {\n\tif !v.Valid {\n\t\treturn fmt.Errorf(\"cannot scan NULL into *uint\")\n\t}\n\n\tbi, err := v.toBigInt()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cannot scan into *uint: %w\", err)\n\t}\n\n\tif !bi.IsUint64() {\n\t\treturn fmt.Errorf(\"cannot scan %v into *uint\", bi.String())\n\t}\n\n\tui := bi.Uint64()\n\n\tif math.MaxUint < ui {\n\t\treturn fmt.Errorf(\"cannot scan %v into *uint\", ui)\n\t}\n\n\t*w = uintWrapper(ui)","sourceCodeStart":264,"sourceCodeEnd":300,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/pgtype/builtin_wrappers.go#L264-L300","documentation":"Returned by uintWrapper.ScanNumeric when the PostgreSQL numeric is NULL (Valid==false) and the destination *uint has no way to represent NULL. Unlike pointer or pgtype wrapper targets, a plain uint cannot store null.","triggerScenarios":"Thrown at pgtype/builtin_wrappers.go:282 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Change the query to use COALESCE with a default value","Scan into *uint only for NOT NULL columns","Use a nullable target such as pgtype.Numeric or a *uint pointer"],"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"}