📄 type_newdecimal.test
字号:
--disable_warningsdrop table if exists t1;--enable_warnings## constant IN function test#select 1.1 IN (1.0, 1.2);select 1.1 IN (1.0, 1.2, 1.1, 1.4, 0.5);select 1.1 IN (1.0, 1.2, NULL, 1.4, 0.5);select 0.5 IN (1.0, 1.2, NULL, 1.4, 0.5);select 1 IN (1.11, 1.2, 1.1, 1.4, 1, 0.5);select 1 IN (1.11, 1.2, 1.1, 1.4, NULL, 0.5);## case function test#select case 1.0 when 0.1 then "a" when 1.0 then "b" else "c" END;select case 0.1 when 0.1 then "a" when 1.0 then "b" else "c" END;select case 1 when 0.1 then "a" when 1.0 then "b" else "c" END;select case 1.0 when 0.1 then "a" when 1 then "b" else "c" END;select case 1.001 when 0.1 then "a" when 1 then "b" else "c" END;## non constant IN test#create table t1 (a decimal(6,3));insert into t1 values (1.0), (NULL), (0.1);select * from t1;select 0.1 in (1.0, 1.2, 1.1, a, 1.4, 0.5) from t1;drop table t1;## if function test#create table t1 select if(1, 1.1, 1.2), if(0, 1.1, 1.2), if(0.1, 1.1, 1.2), if(0, 1, 1.1), if(0, NULL, 1.2), if(1, 0.22e1, 1.1), if(1E0, 1.1, 1.2);select * from t1;show create table t1;drop table t1;## NULLIF#create table t1 select nullif(1.1, 1.1), nullif(1.1, 1.2), nullif(1.1, 0.11e1), nullif(1.0, 1), nullif(1, 1.0), nullif(1, 1.1);select * from t1;show create table t1;drop table t1;## saving in decimal field with overflow#create table t1 (a decimal(4,2));insert into t1 value (10000), (1.1e10), ("11111"), (100000.1);insert into t1 value (-10000), (-1.1e10), ("-11111"), (-100000.1);select a from t1;drop table t1;create table t1 (a decimal(4,2) unsigned);insert into t1 value (10000), (1.1e10), ("11111"), (100000.1);insert into t1 value (-10000), (-1.1e10), ("-11111"), (-100000.1);select a from t1;drop table t1;## saving in field with overflow from decimal#create table t1 (a bigint);insert into t1 values (18446744073709551615.0);insert into t1 values (9223372036854775808.0);insert into t1 values (-18446744073709551615.0);select * from t1;drop table t1;create table t1 (a bigint unsigned);insert into t1 values (18446744073709551615.0);insert into t1 values (9223372036854775808.0);insert into t1 values (9999999999999999999999999.000);insert into t1 values (-1.0);select * from t1;drop table t1;create table t1 (a tinyint);insert into t1 values (18446744073709551615.0);insert into t1 values (9223372036854775808.0);select * from t1;drop table t1;## test that functions create decimal fields#create table t1 select round(15.4,-1), truncate(-5678.123451,-3), abs(-1.1), -(-1.1);show create table t1;drop table t1;## Trydy's tests#set session sql_mode='traditional';select 1e10/0e0;create table wl1612 (col1 int, col2 decimal(38,10), col3 numeric(38,10));insert into wl1612 values(1,12345678901234567890.1234567890,12345678901234567890.1234567890);select * from wl1612;insert into wl1612 values(2,01234567890123456789.0123456789,01234567890123456789.0123456789);select * from wl1612 where col1=2;insert into wl1612 values(3,1234567890123456789012345678.0123456789,1234567890123456789012345678.0123456789);select * from wl1612 where col1=3;select col1/0 from wl1612;select col2/0 from wl1612;select col3/0 from wl1612;insert into wl1612 values(5,5000.0005,5000.0005);insert into wl1612 values(6,5000.0005,5000.0005);select sum(col2),sum(col3) from wl1612;#select avg(col2),avg(col3) from wl1612;insert into wl1612 values(7,500000.000005,500000.000005);insert into wl1612 values(8,500000.000005,500000.000005);select sum(col2),sum(col3) from wl1612 where col1>4;#select avg(col2),avg(col3) from wl1612 where col1>4;#insert into wl1612 (col1,col2) values(9,123456789012345678901234567890);#insert into wl1612 (col1,col3) values(9,123456789012345678901234567890);insert into wl1612 (col1, col2) values(9,1.01234567891);insert into wl1612 (col1, col2) values(10,1.01234567894);insert into wl1612 (col1, col2) values(11,1.01234567895);insert into wl1612 (col1, col2) values(12,1.01234567896);select col1,col2 from wl1612 where col1>8;insert into wl1612 (col1, col3) values(13,1.01234567891);insert into wl1612 (col1, col3) values(14,1.01234567894);insert into wl1612 (col1, col3) values(15,1.01234567895);insert into wl1612 (col1, col3) values(16,1.01234567896);select col1,col3 from wl1612 where col1>12;select col1 from wl1612 where col1>4 and col2=1.01234567891;#-- should return 0 rows#select col1 from wl1612 where col1>4 and col2=1.0123456789;#-- should return col1 values 9 & 10#select col1 from wl1612 where col1>4 and col2<>1.0123456789;#-- should return col1 values 5,6,7,8,11,12#select col1 from wl1612 where col1>4 and col2<1.0123456789;#-- should return 0 rows#select col1 from wl1612 where col1>4 and col2<=1.0123456789;#-- should return col1 values 9 & 10#select col1 from wl1612 where col1>4 and col2>1.0123456789;#-- should return col1 values 5,6,7,8,11,12#select col1 from wl1612 where col1>4 and col2>=1.0123456789;#-- should return col1 values 5,6,7,8,910,11,12##select col1, col2 from wl1612 where col1=11 or col1=12;select col1 from wl1612 where col1>4 and col2=1.012345679;#-- should return col1 values 11,12#select col1 from wl1612 where col1>4 and col2<>1.012345679;#-- should return col1 values 5,6,7,8,9,10#select col1 from wl1612 where col1>4 and col3=1.01234567891;#-- should return 0 rows#select col1 from wl1612 where col1>4 and col3=1.0123456789;#-- should return col1 values 13,14#select col1 from wl1612 where col1>4 and col3<>1.0123456789;#-- should return col1 values 5,6,7,8,15,16#select col1 from wl1612 where col1>4 and col3<1.0123456789;#-- should return 0 rows#select col1 from wl1612 where col1>4 and col3<=1.0123456789;#-- should return col1 values 13,14#select col1 from wl1612 where col1>4 and col3>1.0123456789;#-- should return col1 values 5,6,7,8,15,16#select col1 from wl1612 where col1>4 and col3>=1.0123456789;#-- should return col1 values 5,6,7,8,13,14,15,16#select col1 from wl1612 where col1>4 and col3=1.012345679;#-- should return col1 values 15,16#select col1 from wl1612 where col1>4 and col3<>1.012345679;#-- should return col1 values 5,6,7,8,13,14#drop table wl1612;#select 1/3;#select 0.8=0.7+0.1;#-- should return 1 (true)#select 0.7+0.1;#create table wl1612_1 (col1 int);insert into wl1612_1 values(10);#select * from wl1612_1 where 0.8=0.7+0.1;#--should return 1 row (col1=10)#select 0.07+0.07 from wl1612_1;#select 0.07-0.07 from wl1612_1;#select 0.07*0.07 from wl1612_1;#select 0.07/0.07 from wl1612_1;#drop table wl1612_1;#create table wl1612_2 (col1 decimal(10,2), col2 numeric(10,2));insert into wl1612_2 values(1,1);insert into wl1612_2 values(+1,+1);insert into wl1612_2 values(+01,+01);insert into wl1612_2 values(+001,+001);#select col1,count(*) from wl1612_2 group by col1;#select col2,count(*) from wl1612_2 group by col2;#drop table wl1612_2;#create table wl1612_3 (col1 decimal(10,2), col2 numeric(10,2));insert into wl1612_3 values('1','1');insert into wl1612_3 values('+1','+1');#insert into wl1612_3 values('+01','+01');insert into wl1612_3 values('+001','+001');#select col1,count(*) from wl1612_3 group by col1;#select col2,count(*) from wl1612_3 group by col2;#drop table wl1612_3;#select mod(234,10) ;#-- should return 4#select mod(234.567,10.555);#-- should return 2.357#select mod(-234.567,10.555);#-- should return -2.357#select mod(234.567,-10.555);#-- should return 2.357#select round(15.1);#-- should return 15#select round(15.4);#-- should return 15#select round(15.5);#-- should return 16#select round(15.6);#-- should return 16#select round(15.9);#-- should return 16#select round(-15.1);#-- should return -15#select round(-15.4);#-- should return -15#select round(-15.5);#-- should return -16#select round(-15.6);#-- should return -16#select round(-15.9);#-- should return -16#select round(15.1,1);#-- should return 15.1#select round(15.4,1);#-- should return 15.4#select round(15.5,1);#-- should return 15.5#select round(15.6,1);#-- should return 15.6#select round(15.9,1);#-- should return 15.9#select round(-15.1,1);#-- should return -15.1#select round(-15.4,1);#-- should return -15.4#select round(-15.5,1);#-- should return -15.5#select round(-15.6,1);#-- should return -15.6#select round(-15.9,1);#-- should return -15.9#select round(15.1,0);#-- should return 15#select round(15.4,0);#-- should return 15#select round(15.5,0);#-- should return 16#select round(15.6,0);#-- should return 16#select round(15.9,0);#-- should return 16#select round(-15.1,0);#-- should return -15#select round(-15.4,0);#-- should return -15#select round(-15.5,0);#-- should return -16#select round(-15.6,0);#-- should return -16#select round(-15.9,0);#-- should return -16#select round(15.1,-1);#-- should return 20#select round(15.4,-1);#-- should return 20#select round(15.5,-1);#-- should return 20#select round(15.6,-1);#-- should return 20#select round(15.9,-1);#-- should return 20#select round(-15.1,-1);#-- should return -20#select round(-15.4,-1);#-- should return -20#select round(-15.5,-1);#-- should return -20#select round(-15.6,-1);#-- should return -20#select round(-15.91,-1);#-- should return -20#select truncate(5678.123451,0);#-- should return 5678#select truncate(5678.123451,1);#-- should return 5678.1#select truncate(5678.123451,2);#-- should return 5678.12#select truncate(5678.123451,3);#-- should return 5678.123#select truncate(5678.123451,4);#-- should return 5678.1234#select truncate(5678.123451,5);#-- should return 5678.12345#select truncate(5678.123451,6);#-- should return 5678.123451#select truncate(5678.123451,-1);#-- should return 5670#select truncate(5678.123451,-2);#-- should return 5600#select truncate(5678.123451,-3);#-- should return 5000#select truncate(5678.123451,-4);#-- should return 0#select truncate(-5678.123451,0);#-- should return -5678#select truncate(-5678.123451,1);#-- should return -5678.1#select truncate(-5678.123451,2);#-- should return -5678.12#select truncate(-5678.123451,3);#-- should return -5678.123#select truncate(-5678.123451,4);#-- should return -5678.1234#select truncate(-5678.123451,5);#-- should return -5678.12345#select truncate(-5678.123451,6);#-- should return -5678.123451#select truncate(-5678.123451,-1);#-- should return -5670#select truncate(-5678.123451,-2);#-- should return -5600#select truncate(-5678.123451,-3);#-- should return -5000#select truncate(-5678.123451,-4);#-- should return 0##drop table if exists wl1612_4;create table wl1612_4 (col1 int, col2 decimal(30,25), col3 numeric(30,25));#insert into wl1612_4 values(1,0.0123456789012345678912345,0.0123456789012345678912345);#select col2/9999999999 from wl1612_4 where col1=1;#select col3/9999999999 from wl1612_4 where col1=1;#select 9999999999/col2 from wl1612_4 where col1=1;#select 9999999999/col3 from wl1612_4 where col1=1;#select col2*9999999999 from wl1612_4 where col1=1;#select col3*9999999999 from wl1612_4 where col1=1;#insert into wl1612_4 values(2,55555.0123456789012345678912345,55555.0123456789012345678912345);#select col2/9999999999 from wl1612_4 where col1=2;#select col3/9999999999 from wl1612_4 where col1=2;#select 9999999999/col2 from wl1612_4 where col1=2;#select 9999999999/col3 from wl1612_4 where col1=2;#select col2*9999999999 from wl1612_4 where col1=2;#select col3*9999999999 from wl1612_4 where col1=2;#drop table wl1612_4;#####-- Additional tests for WL#1612 Precision math##-- Comparisons should show that a number is#-- exactly equal to its value as displayed.#set sql_mode='';#select 23.4 + (-41.7), 23.4 - (41.7) = -18.3;#select -18.3=-18.3;#select 18.3=18.3;#select -18.3=18.3;#select 0.8 = 0.7 + 0.1;##-- It should be possible to define a column#-- with up to 38 digits precision either before#-- or after the decimal point. Any number which#-- is inserted, if it's within the range, should#-- be exactly the same as the number that gets#-- selected.#drop table if exists t1;#create table t1 (col1 decimal(38));#insert into t1 values (12345678901234567890123456789012345678);#select * from t1;#-- should return:#+----------------------------------------+#| col1 |#+----------------------------------------+#| 12345678901234567890123456789012345678 |#+----------------------------------------+##drop table t1;##create table t1 (col1 decimal(38,38));##insert into t1 values (.12345678901234567890123456789012345678);##select * from t1;#-- should return:#+------------------------------------------+#| col1 |#+------------------------------------------+#| 0.12345678901234567890123456789012345678 |#+------------------------------------------+#drop table t1;#create table t1 (col1 decimal(31,30));#insert into t1 values (0.00000000001);#select * from t1;#-- should return:#+---------------+#|col1 |#+---------------+#| 0.00000000001 |#+---------------+#drop table t1;##-- The usual arithmetic operators / * + - should work.##select 77777777777777777777777777777777777777 / 7777777777777777777777777777777777777 = 10;#-- should return 0 (false).#select 7777777777777777777777777777777777777 * 10;#-- should return 77777777777777777777777777777777777770
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -