{"record":{"id":"cfca058f32d2483b","repo":"jackc/pgx","slug":"cannot-scan-null-into-t-cfca05","errorCode":null,"errorMessage":"cannot scan NULL into %T","messagePattern":"cannot scan NULL into %T","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pgtype/json.go","lineNumber":211,"sourceCode":"}\n\ntype scanPlanJSONToJSONUnmarshal struct {\n\tunmarshal func(data []byte, v any) error\n}\n\nfunc (s *scanPlanJSONToJSONUnmarshal) Scan(src []byte, dst any) error {\n\tif src == nil {\n\t\tdstValue := reflect.ValueOf(dst)\n\t\tif dstValue.Kind() == reflect.Pointer {\n\t\t\tel := dstValue.Elem()\n\t\t\tswitch el.Kind() {\n\t\t\tcase reflect.Pointer, reflect.Slice, reflect.Map, reflect.Interface:\n\t\t\t\tel.Set(reflect.Zero(el.Type()))\n\t\t\t\treturn nil\n\t\t\t}\n\t\t}\n\n\t\treturn fmt.Errorf(\"cannot scan NULL into %T\", dst)\n\t}\n\n\tv := reflect.ValueOf(dst)\n\tif v.Kind() != reflect.Pointer || v.IsNil() {\n\t\treturn fmt.Errorf(\"cannot scan into non-pointer or nil destinations %T\", dst)\n\t}\n\n\telem := v.Elem()\n\telem.Set(reflect.Zero(elem.Type()))\n\n\treturn s.unmarshal(src, dst)\n}\n\nfunc (c *JSONCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error) {\n\tif src == nil {\n\t\treturn nil, nil\n\t}\n","sourceCodeStart":193,"sourceCodeEnd":229,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/pgtype/json.go#L193-L229","documentation":"This error is returned by the JSON scan plan for types decoded via a custom Unmarshal function when a SQL NULL arrives and the destination cannot represent NULL. The code first tries to zero the pointed-to value (setting nil for pointer, slice, map, and interface element kinds); this error only fires when the destination is a pointer to something else (e.g. *struct or *int), where there is no meaningful zero NULL representation, so decoding is refused.","triggerScenarios":"Thrown at pgtype/json.go:211 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Scan into a pointer, slice, map, or interface destination, which the plan can zero on NULL","Wrap the target type in a Go pointer (e.g. **MyStruct) so NULL can be stored as nil","Change the SQL query with COALESCE or a default so NULL never reaches the scanner","Pre-filter NULLs in the query using WHERE col IS NOT NULL"],"exampleFix":null,"handlingStrategy":"type-guard","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"}