{"record":{"id":"156bd58052dd09cd","repo":"jackc/pgx","slug":"cannot-losslessly-convert-v-to-int64","errorCode":null,"errorMessage":"cannot losslessly convert %v to int64","messagePattern":"cannot losslessly convert (.+?) to int64","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pgtype/float4.go","lineNumber":258,"sourceCode":"type scanPlanBinaryFloat4ToInt64Scanner struct{}\n\nfunc (scanPlanBinaryFloat4ToInt64Scanner) Scan(src []byte, dst any) error {\n\ts := (dst).(Int64Scanner)\n\n\tif src == nil {\n\t\treturn s.ScanInt64(Int8{})\n\t}\n\n\traw, err := pgio.Uint32Exact(src)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"float4: %w\", err)\n\t}\n\n\tui32 := int32(raw)\n\tf32 := math.Float32frombits(uint32(ui32))\n\ti64 := int64(f32)\n\tif f32 != float32(i64) {\n\t\treturn fmt.Errorf(\"cannot losslessly convert %v to int64\", f32)\n\t}\n\n\treturn s.ScanInt64(Int8{Int64: i64, Valid: true})\n}\n\ntype scanPlanBinaryFloat4ToTextScanner struct{}\n\nfunc (scanPlanBinaryFloat4ToTextScanner) Scan(src []byte, dst any) error {\n\ts := (dst).(TextScanner)\n\n\tif src == nil {\n\t\treturn s.ScanText(Text{})\n\t}\n\n\traw, err := pgio.Uint32Exact(src)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"float4: %w\", err)\n\t}","sourceCodeStart":240,"sourceCodeEnd":276,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/pgtype/float4.go#L240-L276","documentation":"Returned by the binary float4-to-Int64Scanner plan when the decoded float32 has a fractional part or magnitude that cannot round-trip through int64. The conversion is deliberately lossless-only: if float32(int64(f)) != f the scan fails.","triggerScenarios":"Thrown at pgtype/float4.go:258 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Scan into a float target (float32/float64/Float8) instead of an integer one","Round the value in SQL (e.g. round()) before scanning","Use pgtype.Numeric for exact decimal handling"],"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"}