v.21.3Improvement

Allow Inaccurate Conversion for JSONExtract to Float32 Type

If user calls JSONExtract function with Float32 type requested, allow inaccurate conversion to the result type. For example the number 0.1 in 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).
Allows the JSONExtract function to perform imprecise conversion when extracting Float32 values from JSON, returning the closest approximate value instead of 0 or NULL for non-representable numbers.

Why it matters

Previously, extracting Float32 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 the JSONExtract 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.