blob: cda812656c20865be664138fce668fb11f75c227 [file] [log] [blame]
# name: test/sql/types/decimal/decimal_overflow.test
# description: Test overflow in various decimal computations
# group: [decimal]
statement ok
PRAGMA enable_verification
query I
select (99000000000000000.0::DECIMAL(18,1)+99000000000000000.0::DECIMAL(18,1));
----
198000000000000000.0
statement error
select (99000000000000000.0::DECIMAL(18,1)+99000000000000000.0::DECIMAL(18,1))::VARCHAR::DECIMAL(18,1);
query I
select (50000000000000000.0::DECIMAL(18,1)+50000000000000000.0::DECIMAL(18,1));
----
100000000000000000.0
query I
select (-99000000000000000.0::DECIMAL(18,1)-99000000000000000.0::DECIMAL(18,1));
----
-198000000000000000.0
query I
select (-50000000000000000.0::DECIMAL(18,1)-50000000000000000.0::DECIMAL(18,1));
----
-100000000000000000.0
# decimals can overflow at the hugeint boundary, because we run out of bits
query I
select (9900000000000000000000000000000000000.0::DECIMAL(38,1)+9900000000000000000000000000000000000.0::DECIMAL(38,1));
----
19800000000000000000000000000000000000.0
query I
select (5000000000000000000000000000000000000.0::DECIMAL(38,1)+5000000000000000000000000000000000000.0::DECIMAL(38,1));
----
10000000000000000000000000000000000000.0
statement error
select '10000000000000000000000000000000000000.0'::DECIMAL(38,1);
query I
select (-5000000000000000000000000000000000000.0::DECIMAL(38,1)-5000000000000000000000000000000000000.0::DECIMAL(38,1));
----
-10000000000000000000000000000000000000.0
# decimals can overflow in multiplications
# bigint
query I
select 90000000000000000.0::DECIMAL(18,1) * 10::DECIMAL(2,0);
----
900000000000000000.0
query I
select 90000000000000000.0::DECIMAL(18,1) * 1000::DECIMAL(4,0);
----
90000000000000000000.0
# hugeint
query I
select 5000000000000000000000000000000000000.0::DECIMAL(38,1) * 2::DECIMAL(1,0);
----
10000000000000000000000000000000000000.0
# but also like this... the type of this multiplication becomes DECIMAL(38,2), which does not fit 9900000000000000000000000000000000000
query I
select 9900000000000000000000000000000000000.0::DECIMAL(38,1) * 1.0;
----
9900000000000000000000000000000000000.00