diff --git a/src/query/expression/src/type_check.rs b/src/query/expression/src/type_check.rs index d5ac3592af173..4151559d82d50 100755 --- a/src/query/expression/src/type_check.rs +++ b/src/query/expression/src/type_check.rs @@ -559,11 +559,10 @@ pub fn can_auto_cast_to( .zip(dest_tys) .all(|(src_ty, dest_ty)| can_auto_cast_to(src_ty, dest_ty, auto_cast_rules)) } - (DataType::Number(n), DataType::Decimal(_)) if !n.is_float() => true, (DataType::String, DataType::Decimal(_)) => true, (DataType::Decimal(x), DataType::Decimal(y)) => x.precision() <= y.precision(), - (DataType::Decimal(_), DataType::Number(NumberDataType::Float32)) => true, - (DataType::Decimal(_), DataType::Number(NumberDataType::Float64)) => true, + (DataType::Number(n), DataType::Decimal(_)) if !n.is_float() => true, + (DataType::Decimal(_), DataType::Number(n)) if n.is_float() => true, _ => false, } } @@ -602,11 +601,18 @@ pub fn common_super_type( .collect::>>()?; Some(DataType::Tuple(tys)) } - (DataType::Number(_), DataType::Decimal(ty)) - | (DataType::Decimal(ty), DataType::Number(_)) => { - let max_precision = ty.max_precision(); - let scale = ty.scale(); - + (DataType::String, decimal_ty @ DataType::Decimal(_)) + | (decimal_ty @ DataType::Decimal(_), DataType::String) => Some(decimal_ty), + (DataType::Decimal(a), DataType::Decimal(b)) => { + let ty = DecimalDataType::binary_result_type(&a, &b, false, false, true).ok(); + ty.map(DataType::Decimal) + } + (DataType::Number(num_ty), DataType::Decimal(decimal_ty)) + | (DataType::Decimal(decimal_ty), DataType::Number(num_ty)) + if !num_ty.is_float() => + { + let max_precision = decimal_ty.max_precision(); + let scale = decimal_ty.scale(); DecimalDataType::from_size(DecimalSize { precision: max_precision, scale, @@ -614,12 +620,12 @@ pub fn common_super_type( .ok() .map(DataType::Decimal) } - - (DataType::Decimal(a), DataType::Decimal(b)) => { - let ty = DecimalDataType::binary_result_type(&a, &b, false, false, true).ok(); - ty.map(DataType::Decimal) + (DataType::Number(num_ty), DataType::Decimal(_)) + | (DataType::Decimal(_), DataType::Number(num_ty)) + if num_ty.is_float() => + { + Some(DataType::Number(num_ty)) } - (ty1, ty2) => { let ty1_can_cast_to = auto_cast_rules .iter()