2023-03-14 23:38:46 +00:00
-- { echoOn }
SELECT 1.1::Decimal(60, 30);
2023-03-14 21:11:45 +00:00
1.1
2023-03-14 23:38:46 +00:00
SELECT round(1.1::Decimal(60, 30));
2023-03-14 21:11:45 +00:00
1
2023-03-14 23:38:46 +00:00
SELECT round(1.1::Decimal(60, 30), 1);
2023-03-14 21:11:45 +00:00
1.1
2023-03-14 23:38:46 +00:00
SELECT round(1.234567890123456789012345678901::Decimal(60, 30), 1);
2023-03-14 21:11:45 +00:00
1.2
2023-03-14 23:38:46 +00:00
SELECT round(1.234567890123456789012345678901::Decimal(60, 30), 30);
2023-03-14 21:11:45 +00:00
1.234567890123456789012345678901
2023-03-14 23:38:46 +00:00
SELECT round(1.234567890123456789012345678901::Decimal(60, 30), 31);
2023-03-14 21:11:45 +00:00
1.234567890123456789012345678901
2023-03-14 23:38:46 +00:00
SELECT round(1.234567890123456789012345678901::Decimal(60, 30), 20);
2023-03-14 21:11:45 +00:00
1.23456789012345678901
2023-03-14 23:38:46 +00:00
SELECT hex(1.234567890123456789012345678901::Decimal(60, 30));
2023-03-14 21:11:45 +00:00
356C760E4FC986A2A39F1A950F00000000000000000000000000000000000000
2023-03-14 23:38:46 +00:00
SELECT bin(1.234567890123456789012345678901::Decimal(60, 30));
2023-03-14 21:11:45 +00:00
0011010101101100011101100000111001001111110010011000011010100010101000111001111100011010100101010000111100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
2023-03-14 23:38:46 +00:00
SELECT reinterpret(unhex(hex(1.234567890123456789012345678901::Decimal(60, 30))), 'Decimal(60, 30)');
2023-03-14 21:11:45 +00:00
1.234567890123456789012345678901
2023-03-14 23:38:46 +00:00
SELECT arraySum([1.2::Decimal(60, 30), 3.45::Decimal(61, 29)]);
2023-03-14 21:11:45 +00:00
4.65
2023-03-14 23:38:46 +00:00
SELECT arraySum([1.2::Decimal(60, 30), 3.45::Decimal(3, 2)]);
2023-03-14 21:11:45 +00:00
4.65
2023-03-14 23:38:46 +00:00
SELECT arrayMin([1.2::Decimal(60, 30), 3.45::Decimal(61, 29)]);
1.2
SELECT arrayMax([1.2::Decimal(60, 30), 3.45::Decimal(61, 29)]);
3.45
SELECT arrayAvg([1.2::Decimal(60, 30), 3.45::Decimal(61, 29)]);
2.325
SELECT round(arrayProduct([1.2::Decimal(60, 30), 3.45::Decimal(61, 29)]), 6);
4.14
SELECT toTypeName(arrayProduct([1.2::Decimal(60, 30), 3.45::Decimal(61, 29)]));
Float64
SELECT arrayCumSum([1.2::Decimal(60, 30), 3.45::Decimal(61, 29)]);
[1.2,4.65]
SELECT arrayCumSumNonNegative([1.2::Decimal(60, 30), 3.45::Decimal(61, 29)]);
[1.2,4.65]
SELECT arrayDifference([1.2::Decimal(60, 30), 3.45::Decimal(61, 29)]);
[0,2.25]
SELECT arrayCompact([1.2::Decimal(60, 30) AS x, x, x, x, 3.45::Decimal(3, 2) AS y, y, x, x]);
2023-03-14 21:11:45 +00:00
[1.2,3.45,1.2]
2023-03-14 23:38:46 +00:00
SELECT 1.2::Decimal(2, 1) IN (1.2::Decimal(60, 30), 3.4::Decimal(60, 30));
2023-03-14 21:11:45 +00:00
1
2023-03-14 23:38:46 +00:00
SELECT 1.23::Decimal(3, 2) IN (1.2::Decimal(60, 30), 3.4::Decimal(60, 30));
2023-03-14 21:11:45 +00:00
0
2023-03-14 23:38:46 +00:00
SELECT 1.2::Decimal(60, 30) IN (1.2::Decimal(2, 1));
2023-03-14 21:11:45 +00:00
1
2023-03-14 23:38:46 +00:00
SELECT toTypeName([1.2::Decimal(60, 30), 3.45::Decimal(3, 2)]);
2023-03-14 21:11:45 +00:00
Array(Decimal(76, 30))
2023-03-14 23:38:46 +00:00
SELECT toTypeName(arraySum([1.2::Decimal(60, 30), 3.45::Decimal(3, 2)]));
2023-03-14 21:11:45 +00:00
Decimal(76, 30)
2023-03-14 23:38:46 +00:00
SELECT arrayJoin(sumMap(x)) FROM (SELECT [('Hello', 1.2::Decimal256(30)), ('World', 3.4::Decimal256(30))]::Map(String, Decimal256(30)) AS x UNION ALL SELECT [('World', 5.6::Decimal256(30)), ('GoodBye', -111.222::Decimal256(30))]::Map(String, Decimal256(30))) ORDER BY 1;
('GoodBye',-111.222)
('Hello',1.2)
('World',9)
SELECT mapAdd(map('Hello', 1.2::Decimal128(30), 'World', 3.4::Decimal128(30)), map('World', 5.6::Decimal128(30), 'GoodBye', -111.222::Decimal128(30)));
{'GoodBye':-111.222,'Hello':1.2,'World':9}
SELECT mapSubtract(map('Hello', 1.2::Decimal128(30), 'World', 3.4::Decimal128(30)), map('World', 5.6::Decimal128(30), 'GoodBye', -111.222::Decimal128(30)));
{'GoodBye':111.222,'Hello':1.2,'World':-2.2}
SELECT arraySort(arrayIntersect([1, 2, 3]::Array(UInt256), [2, 3, 4]::Array(UInt256)));
[2,3]
SELECT toTypeName(arraySort(arrayIntersect([1, 2, 3]::Array(UInt256), [2, 3, 4]::Array(UInt128))));
Array(UInt128)
SELECT toTypeName(arraySort(arrayIntersect([1, 2, 3]::Array(UInt256), [2, 3, 4]::Array(Int128))));
Array(Int128)
SELECT arraySort(arrayIntersect([1, 2, 3]::Array(UInt256), [2, 3, 4]::Array(Int128)));
[2,3]
SELECT arraySort(arrayIntersect([1, 2, 3]::Array(UInt256), [2, 3, 4]::Array(Int8)));
[2,3]
SELECT toTypeName(arraySort(arrayIntersect([1, 2, 3]::Array(UInt256), [2, 3, 4]::Array(Int8))));
Array(Int8)
SELECT arraySort(arrayIntersect([1.1::Decimal256(70), 2.34::Decimal256(60), 3.456::Decimal256(50)], [2.34::Decimal256(65), 3.456::Decimal256(55), 4.5678::Decimal256(45)]));
[2.34,3.456]
SELECT arraySort(arrayIntersect([1.1::Decimal256(1)], [1.12::Decimal256(2)])); -- Note: this is correct but the semantics has to be clarified in the docs.
[1.1]
SELECT arraySort(arrayIntersect([1.1::Decimal256(2)], [1.12::Decimal256(2)]));
[]
SELECT arraySort(arrayIntersect([1.1::Decimal128(1)], [1.12::Decimal128(2)])); -- Note: this is correct but the semantics has to be clarified in the docs.
[1.1]
SELECT arraySort(arrayIntersect([1.1::Decimal128(2)], [1.12::Decimal128(2)]));
[]
2023-03-15 01:29:07 +00:00
select coalesce(cast('123', 'Nullable(Decimal(20, 10))'), 0);
123
select coalesce(cast('123', 'Nullable(Decimal(40, 10))'), 0);
123
select coalesce(cast('123', 'Decimal(40, 10)'), 0);
123
2023-03-15 01:35:41 +00:00
DROP TABLE IF EXISTS decimal_insert_cast_issue;
create table decimal_insert_cast_issue (a Decimal(76, 0)) engine = TinyLog;
SET param_param = 1;
INSERT INTO decimal_insert_cast_issue VALUES ({param:Nullable(Decimal(41, 0))});
SELECT * FROM decimal_insert_cast_issue;
1
DROP TABLE decimal_insert_cast_issue;