v.21.3Improvement
Allow Inaccurate Conversion for JSONExtract to Float32 Type
If user callsJSONExtractfunction withFloat32type requested, allow inaccurate conversion to the result type. For example the number0.1in JSON is double precision and is not representable in Float32, but the user still wants to get it. Previous versions return 0 for non-Nullable type and NULL for Nullable type to indicate that conversion is imprecise. The logic was 100% correct but it was surprising to users and leading to questions. This closes #13962. #19960 (alexey-milovidov).
Why it matters
Previously, extractingFloat32 values from JSON that could not be exactly represented (e.g., 0.1) resulted in 0 for non-Nullable types and NULL for Nullable types, which was surprising and confusing for users. This feature improves usability by allowing approximate conversion, providing users with expected float approximations rather than defaulting to zero or NULL, thereby resolving related user concerns and questions.How to use it
Users can simply continue using theJSONExtract function with Float32 as the requested type. The function will now automatically allow imprecise conversions, returning the closest Float32 approximation of the JSON number without additional configuration.