mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 00:22:29 +00:00
fix int field to decimal conversion
This commit is contained in:
parent
ac477d9850
commit
4859657c42
@ -120,14 +120,17 @@ public:
|
||||
return DecimalUtils::getFractionalPart(x, scale);
|
||||
}
|
||||
|
||||
T maxWholeValue() const { return getScaleMultiplier(maxPrecision() - scale) - T(1); }
|
||||
T maxWholeValue() const { return getScaleMultiplier(precision - scale) - T(1); }
|
||||
|
||||
bool canStoreWhole(T x) const
|
||||
template<typename U>
|
||||
bool canStoreWhole(U x) const
|
||||
{
|
||||
static_assert(std::is_signed_v<typename T::NativeType>);
|
||||
T max = maxWholeValue();
|
||||
if (x > max || x < -max)
|
||||
return false;
|
||||
return true;
|
||||
if constexpr (std::is_signed_v<U>)
|
||||
return -max <= x && x <= max;
|
||||
else
|
||||
return x <= static_cast<std::make_unsigned_t<typename T::NativeType>>(max.value);
|
||||
}
|
||||
|
||||
/// @returns multiplier for U to become T with correct scale
|
||||
|
@ -0,0 +1,2 @@
|
||||
9.00000000
|
||||
10.00000000
|
10
tests/queries/0_stateless/01178_int_field_to_decimal.sql
Normal file
10
tests/queries/0_stateless/01178_int_field_to_decimal.sql
Normal file
@ -0,0 +1,10 @@
|
||||
select d from values('d Decimal(8, 8)', 0, 1) where d not in (-1, 0); -- { serverError 69 }
|
||||
select d from values('d Decimal(8, 8)', 0, 2) where d not in (1, 0); -- { serverError 69 }
|
||||
select d from values('d Decimal(9, 8)', 0, 3) where d not in (-9223372036854775808, 0); -- { serverError 69 }
|
||||
select d from values('d Decimal(9, 8)', 0, 4) where d not in (18446744073709551615, 0); -- { serverError 69 }
|
||||
select d from values('d Decimal(18, 8)', 0, 5) where d not in (-9223372036854775808, 0); -- { serverError 69 }
|
||||
select d from values('d Decimal(18, 8)', 0, 6) where d not in (18446744073709551615, 0); -- { serverError 69 }
|
||||
select d from values('d Decimal(26, 8)', 0, 7) where d not in (-9223372036854775808, 0); -- { serverError 69 }
|
||||
select d from values('d Decimal(27, 8)', 0, 8) where d not in (18446744073709551615, 0); -- { serverError 69 }
|
||||
select d from values('d Decimal(27, 8)', 0, 9) where d not in (-9223372036854775808, 0);
|
||||
select d from values('d Decimal(28, 8)', 0, 10) where d not in (18446744073709551615, 0);
|
Loading…
Reference in New Issue
Block a user