{"id":"2744185c22fe112c","repo":"jackc/pgx","slug":"cannot-encode-v-as-element-of-range","errorCode":null,"errorMessage":"cannot encode %v as element of range","messagePattern":"cannot encode (.+?) as element of range","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pgtype/range_codec.go","lineNumber":118,"sourceCode":"\t\trangeType |= upperUnboundedMask\n\tcase Exclusive:\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"unknown UpperType: %v\", upperType)\n\t}\n\n\tbuf = append(buf, rangeType)\n\n\tif lowerType != Unbounded {\n\t\tif lower == nil {\n\t\t\treturn nil, fmt.Errorf(\"Lower cannot be NULL unless LowerType is Unbounded\")\n\t\t}\n\n\t\tsp := len(buf)\n\t\tbuf = pgio.AppendInt32(buf, -1)\n\n\t\tlowerPlan := plan.m.PlanEncode(plan.rc.ElementType.OID, BinaryFormatCode, lower)\n\t\tif lowerPlan == nil {\n\t\t\treturn nil, fmt.Errorf(\"cannot encode %v as element of range\", lower)\n\t\t}\n\n\t\tbuf, err = lowerPlan.Encode(lower, buf)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to encode %v as element of range: %w\", lower, err)\n\t\t}\n\t\tif buf == nil {\n\t\t\treturn nil, fmt.Errorf(\"Lower cannot be NULL unless LowerType is Unbounded\")\n\t\t}\n\n\t\tpgio.SetInt32(buf[sp:], int32(len(buf[sp:])-4))\n\t}\n\n\tif upperType != Unbounded {\n\t\tif upper == nil {\n\t\t\treturn nil, fmt.Errorf(\"Upper cannot be NULL unless UpperType is Unbounded\")\n\t\t}\n","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/pgtype/range_codec.go#L100-L136","documentation":"Error \"cannot encode %v as element of range\" thrown in jackc/pgx.","triggerScenarios":"Thrown at pgtype/range_codec.go:118 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"ec1a0befd22592cffffdeeb0a50311b506372f4c","analyzedAt":"2026-08-04T22:52:11.263Z","schemaVersion":2}