blob: a6a50c6a2abe4ca30bbc842a68fd6d5866f21a6e [file] [log] [blame]
# name: test/sql/types/decimal/test_decimal_cast.test
# description: Exhaustively test many decimal cast combinations
# group: [decimal]
statement ok
PRAGMA enable_verification
# test various decimal to decimal casts
loop i 2 38
# target = smallint
# test casts with same scale
query I
SELECT ('1'::DECIMAL(${i}, 0))::DECIMAL(1,0)
----
1
# test casts with lower scale
query I
SELECT ('1'::DECIMAL(${i}, 1))::DECIMAL(1,0)
----
1
# test casts with higher scale
query I
SELECT ('1'::DECIMAL(${i}, 0))::DECIMAL(2,1)
----
1
# target = integer
# test casts with same scale
query I
SELECT ('1'::DECIMAL(${i}, 0))::DECIMAL(9,0)
----
1
# test casts with lower scale
query I
SELECT ('1'::DECIMAL(${i}, 1))::DECIMAL(9,0)
----
1
# test casts with higher scale
query I
SELECT ('1'::DECIMAL(${i}, 0))::DECIMAL(9,1)
----
1
# target = bigint
# test casts with same scale
query I
SELECT ('1'::DECIMAL(${i}, 0))::DECIMAL(18,0)
----
1
# test casts with lower scale
query I
SELECT ('1'::DECIMAL(${i}, 1))::DECIMAL(18,0)
----
1
# test casts with higher scale
query I
SELECT ('1'::DECIMAL(${i}, 0))::DECIMAL(18,1)
----
1
# target = hugeint
# test casts with same scale
query I
SELECT ('1'::DECIMAL(${i}, 0))::DECIMAL(38,0)
----
1
# test casts with lower scale
query I
SELECT ('1'::DECIMAL(${i}, 1))::DECIMAL(38,0)
----
1
# test casts with higher scale
query I
SELECT ('1'::DECIMAL(${i}, 0))::DECIMAL(38,1)
----
1
endloop