{"record":{"id":"b9697adee2fef4fe","repo":"jackc/pgx","slug":"cannot-scan-null-to-string","errorCode":null,"errorMessage":"cannot scan NULL to string","messagePattern":"cannot scan NULL to string","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pgtype/builtin_wrappers.go","lineNumber":627,"sourceCode":"\ntype mapStringToPointerStringWrapper map[string]*string\n\nfunc (w *mapStringToPointerStringWrapper) ScanHstore(v Hstore) error {\n\t*w = mapStringToPointerStringWrapper(v)\n\treturn nil\n}\n\nfunc (w mapStringToPointerStringWrapper) HstoreValue() (Hstore, error) {\n\treturn Hstore(w), nil\n}\n\ntype mapStringToStringWrapper map[string]string\n\nfunc (w *mapStringToStringWrapper) ScanHstore(v Hstore) error {\n\t*w = make(mapStringToStringWrapper, len(v))\n\tfor k, v := range v {\n\t\tif v == nil {\n\t\t\treturn fmt.Errorf(\"cannot scan NULL to string\")\n\t\t}\n\t\t(*w)[k] = *v\n\t}\n\treturn nil\n}\n\nfunc (w mapStringToStringWrapper) HstoreValue() (Hstore, error) {\n\tif w == nil {\n\t\treturn nil, nil\n\t}\n\n\thstore := make(Hstore, len(w))\n\tfor k, v := range w {\n\t\ts := v\n\t\thstore[k] = &s\n\t}\n\treturn hstore, nil\n}","sourceCodeStart":609,"sourceCodeEnd":645,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/pgtype/builtin_wrappers.go#L609-L645","documentation":"ScanHstore hit an hstore key whose value is NULL while building a map[string]string, which cannot store NULL values. The k=v pair with NULL value is the faulting input; use map[string]*string to accept NULL hstore values.","triggerScenarios":"Thrown at pgtype/builtin_wrappers.go:627 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Scan into map[string]*string or pgtype.Hstore, which support NULL values","Fill NULLs in the query side before returning the hstore"],"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"}