~ubuntu-branches/ubuntu/trusty/mysql-5.6/trusty

« back to all changes in this revision

Viewing changes to mysql-test/r/func_math.result

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-02-12 11:54:27 UTC
  • Revision ID: package-import@ubuntu.com-20140212115427-oq6tfsqxl1wuwehi
Tags: upstream-5.6.15
ImportĀ upstreamĀ versionĀ 5.6.15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
drop table if exists t1;
 
2
select floor(5.5),floor(-5.5);
 
3
floor(5.5)      floor(-5.5)
 
4
5       -6
 
5
explain extended select floor(5.5),floor(-5.5);
 
6
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
 
7
1       SIMPLE  NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    No tables used
 
8
Warnings:
 
9
Note    1003    /* select#1 */ select floor(5.5) AS `floor(5.5)`,floor(-(5.5)) AS `floor(-5.5)`
 
10
select ceiling(5.5),ceiling(-5.5);
 
11
ceiling(5.5)    ceiling(-5.5)
 
12
6       -5
 
13
explain extended select ceiling(5.5),ceiling(-5.5);
 
14
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
 
15
1       SIMPLE  NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    No tables used
 
16
Warnings:
 
17
Note    1003    /* select#1 */ select ceiling(5.5) AS `ceiling(5.5)`,ceiling(-(5.5)) AS `ceiling(-5.5)`
 
18
select truncate(52.64,1),truncate(52.64,2),truncate(52.64,-1),truncate(52.64,-2), truncate(-52.64,1),truncate(-52.64,-1);
 
19
truncate(52.64,1)       truncate(52.64,2)       truncate(52.64,-1)      truncate(52.64,-2)      truncate(-52.64,1)      truncate(-52.64,-1)
 
20
52.6    52.64   50      0       -52.6   -50
 
21
explain extended select truncate(52.64,1),truncate(52.64,2),truncate(52.64,-1),truncate(52.64,-2), truncate(-52.64,1),truncate(-52.64,-1);
 
22
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
 
23
1       SIMPLE  NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    No tables used
 
24
Warnings:
 
25
Note    1003    /* select#1 */ select truncate(52.64,1) AS `truncate(52.64,1)`,truncate(52.64,2) AS `truncate(52.64,2)`,truncate(52.64,-(1)) AS `truncate(52.64,-1)`,truncate(52.64,-(2)) AS `truncate(52.64,-2)`,truncate(-(52.64),1) AS `truncate(-52.64,1)`,truncate(-(52.64),-(1)) AS `truncate(-52.64,-1)`
 
26
select round(5.5),round(-5.5);
 
27
round(5.5)      round(-5.5)
 
28
6       -6
 
29
explain extended select round(5.5),round(-5.5);
 
30
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
 
31
1       SIMPLE  NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    No tables used
 
32
Warnings:
 
33
Note    1003    /* select#1 */ select round(5.5,0) AS `round(5.5)`,round(-(5.5),0) AS `round(-5.5)`
 
34
select round(5.64,1),round(5.64,2),round(5.64,-1),round(5.64,-2);
 
35
round(5.64,1)   round(5.64,2)   round(5.64,-1)  round(5.64,-2)
 
36
5.6     5.64    10      0
 
37
select abs(-10), sign(-5), sign(5), sign(0);
 
38
abs(-10)        sign(-5)        sign(5) sign(0)
 
39
10      -1      1       0
 
40
explain extended select abs(-10), sign(-5), sign(5), sign(0);
 
41
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
 
42
1       SIMPLE  NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    No tables used
 
43
Warnings:
 
44
Note    1003    /* select#1 */ select abs(-(10)) AS `abs(-10)`,sign(-(5)) AS `sign(-5)`,sign(5) AS `sign(5)`,sign(0) AS `sign(0)`
 
45
select log(exp(10)),exp(log(sqrt(10))*2),log(-1),log(NULL),log(1,1),log(3,9),log(-1,2),log(NULL,2);
 
46
log(exp(10))    exp(log(sqrt(10))*2)    log(-1) log(NULL)       log(1,1)        log(3,9)        log(-1,2)       log(NULL,2)
 
47
10      10.000000000000002      NULL    NULL    NULL    2       NULL    NULL
 
48
explain extended select log(exp(10)),exp(log(sqrt(10))*2),log(-1),log(NULL),log(1,1),log(3,9),log(-1,2),log(NULL,2);
 
49
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
 
50
1       SIMPLE  NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    No tables used
 
51
Warnings:
 
52
Note    1003    /* select#1 */ select log(exp(10)) AS `log(exp(10))`,exp((log(sqrt(10)) * 2)) AS `exp(log(sqrt(10))*2)`,log(-(1)) AS `log(-1)`,log(NULL) AS `log(NULL)`,log(1,1) AS `log(1,1)`,log(3,9) AS `log(3,9)`,log(-(1),2) AS `log(-1,2)`,log(NULL,2) AS `log(NULL,2)`
 
53
select ln(exp(10)),exp(ln(sqrt(10))*2),ln(-1),ln(0),ln(NULL);
 
54
ln(exp(10))     exp(ln(sqrt(10))*2)     ln(-1)  ln(0)   ln(NULL)
 
55
10      10.000000000000002      NULL    NULL    NULL
 
56
explain extended select ln(exp(10)),exp(ln(sqrt(10))*2),ln(-1),ln(0),ln(NULL);
 
57
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
 
58
1       SIMPLE  NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    No tables used
 
59
Warnings:
 
60
Note    1003    /* select#1 */ select ln(exp(10)) AS `ln(exp(10))`,exp((ln(sqrt(10)) * 2)) AS `exp(ln(sqrt(10))*2)`,ln(-(1)) AS `ln(-1)`,ln(0) AS `ln(0)`,ln(NULL) AS `ln(NULL)`
 
61
select log2(8),log2(15),log2(-2),log2(0),log2(NULL);
 
62
log2(8) log2(15)        log2(-2)        log2(0) log2(NULL)
 
63
3       3.9068905956085187      NULL    NULL    NULL
 
64
explain extended select log2(8),log2(15),log2(-2),log2(0),log2(NULL);
 
65
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
 
66
1       SIMPLE  NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    No tables used
 
67
Warnings:
 
68
Note    1003    /* select#1 */ select log2(8) AS `log2(8)`,log2(15) AS `log2(15)`,log2(-(2)) AS `log2(-2)`,log2(0) AS `log2(0)`,log2(NULL) AS `log2(NULL)`
 
69
select log10(100),log10(18),log10(-4),log10(0),log10(NULL);
 
70
log10(100)      log10(18)       log10(-4)       log10(0)        log10(NULL)
 
71
2       1.255272505103306       NULL    NULL    NULL
 
72
explain extended select log10(100),log10(18),log10(-4),log10(0),log10(NULL);
 
73
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
 
74
1       SIMPLE  NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    No tables used
 
75
Warnings:
 
76
Note    1003    /* select#1 */ select log10(100) AS `log10(100)`,log10(18) AS `log10(18)`,log10(-(4)) AS `log10(-4)`,log10(0) AS `log10(0)`,log10(NULL) AS `log10(NULL)`
 
77
select pow(10,log10(10)),power(2,4);
 
78
pow(10,log10(10))       power(2,4)
 
79
10      16
 
80
explain extended select pow(10,log10(10)),power(2,4);
 
81
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
 
82
1       SIMPLE  NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    No tables used
 
83
Warnings:
 
84
Note    1003    /* select#1 */ select pow(10,log10(10)) AS `pow(10,log10(10))`,pow(2,4) AS `power(2,4)`
 
85
set @@rand_seed1=10000000,@@rand_seed2=1000000;
 
86
select rand(999999),rand();
 
87
rand(999999)    rand()
 
88
0.014231365187309091    0.028870999839968048
 
89
explain extended select rand(999999),rand();
 
90
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
 
91
1       SIMPLE  NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    No tables used
 
92
Warnings:
 
93
Note    1003    /* select#1 */ select rand(999999) AS `rand(999999)`,rand() AS `rand()`
 
94
select pi(),format(sin(pi()/2),6),format(cos(pi()/2),6),format(abs(tan(pi())),6),format(cot(1),6),format(asin(1),6),format(acos(0),6),format(atan(1),6);
 
95
pi()    format(sin(pi()/2),6)   format(cos(pi()/2),6)   format(abs(tan(pi())),6)        format(cot(1),6)        format(asin(1),6)       format(acos(0),6)       format(atan(1),6)
 
96
3.141593        1.000000        0.000000        0.000000        0.642093        1.570796        1.570796        0.785398
 
97
explain extended select pi(),format(sin(pi()/2),6),format(cos(pi()/2),6),format(abs(tan(pi())),6),format(cot(1),6),format(asin(1),6),format(acos(0),6),format(atan(1),6);
 
98
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
 
99
1       SIMPLE  NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    No tables used
 
100
Warnings:
 
101
Note    1003    /* select#1 */ select pi() AS `pi()`,format(sin((pi() / 2)),6) AS `format(sin(pi()/2),6)`,format(cos((pi() / 2)),6) AS `format(cos(pi()/2),6)`,format(abs(tan(pi())),6) AS `format(abs(tan(pi())),6)`,format(cot(1),6) AS `format(cot(1),6)`,format(asin(1),6) AS `format(asin(1),6)`,format(acos(0),6) AS `format(acos(0),6)`,format(atan(1),6) AS `format(atan(1),6)`
 
102
select degrees(pi()),radians(360);
 
103
degrees(pi())   radians(360)
 
104
180     6.283185307179586
 
105
select format(atan(-2, 2), 6);
 
106
format(atan(-2, 2), 6)
 
107
-0.785398
 
108
select format(atan(pi(), 0), 6);
 
109
format(atan(pi(), 0), 6)
 
110
1.570796
 
111
select format(atan2(-2, 2), 6);
 
112
format(atan2(-2, 2), 6)
 
113
-0.785398
 
114
select format(atan2(pi(), 0), 6);
 
115
format(atan2(pi(), 0), 6)
 
116
1.570796
 
117
SELECT ACOS(1.0);
 
118
ACOS(1.0)
 
119
0
 
120
SELECT ASIN(1.0);
 
121
ASIN(1.0)
 
122
1.5707963267948966
 
123
SELECT ACOS(0.2*5.0);
 
124
ACOS(0.2*5.0)
 
125
0
 
126
SELECT ACOS(0.5*2.0);
 
127
ACOS(0.5*2.0)
 
128
0
 
129
SELECT ASIN(0.8+0.2);
 
130
ASIN(0.8+0.2)
 
131
1.5707963267948966
 
132
SELECT ASIN(1.2-0.2);
 
133
ASIN(1.2-0.2)
 
134
1.5707963267948966
 
135
select format(4.55, 1), format(4.551, 1);
 
136
format(4.55, 1) format(4.551, 1)
 
137
4.6     4.6
 
138
explain extended select degrees(pi()),radians(360);
 
139
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
 
140
1       SIMPLE  NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    No tables used
 
141
Warnings:
 
142
Note    1003    /* select#1 */ select degrees(pi()) AS `degrees(pi())`,radians(360) AS `radians(360)`
 
143
select rand(rand);
 
144
ERROR 42S22: Unknown column 'rand' in 'field list'
 
145
create table t1 (col1 int, col2 decimal(60,30));
 
146
insert into t1 values(1,1234567890.12345);
 
147
select format(col2,7) from t1;
 
148
format(col2,7)
 
149
1,234,567,890.1234500
 
150
select format(col2,8) from t1;
 
151
format(col2,8)
 
152
1,234,567,890.12345000
 
153
insert into t1 values(7,1234567890123456.12345);
 
154
select format(col2,6) from t1 where col1=7;
 
155
format(col2,6)
 
156
1,234,567,890,123,456.123450
 
157
drop table t1;
 
158
select ceil(0.09);
 
159
ceil(0.09)
 
160
1
 
161
select ceil(0.000000000000000009);
 
162
ceil(0.000000000000000009)
 
163
1
 
164
create table t1 select round(1, 6);
 
165
show create table t1;
 
166
Table   Create Table
 
167
t1      CREATE TABLE `t1` (
 
168
  `round(1, 6)` int(1) NOT NULL DEFAULT '0'
 
169
) ENGINE=MyISAM DEFAULT CHARSET=latin1
 
170
select * from t1;
 
171
round(1, 6)
 
172
1
 
173
drop table t1;
 
174
select abs(-2) * -2;
 
175
abs(-2) * -2
 
176
-4
 
177
CREATE TABLE t1 (a INT);
 
178
INSERT INTO t1 VALUES (1),(1),(1),(2);
 
179
SELECT CAST(RAND(2) * 1000 AS UNSIGNED), CAST(RAND(a) * 1000 AS UNSIGNED) 
 
180
FROM t1;
 
181
CAST(RAND(2) * 1000 AS UNSIGNED)        CAST(RAND(a) * 1000 AS UNSIGNED)
 
182
656     405
 
183
122     405
 
184
645     405
 
185
858     656
 
186
SELECT CAST(RAND(2) * 1000 AS UNSIGNED), CAST(RAND(a) * 1000 AS UNSIGNED) 
 
187
FROM t1 WHERE a = 1;
 
188
CAST(RAND(2) * 1000 AS UNSIGNED)        CAST(RAND(a) * 1000 AS UNSIGNED)
 
189
656     405
 
190
122     405
 
191
645     405
 
192
INSERT INTO t1 VALUES (3);
 
193
SELECT CAST(RAND(2) * 1000 AS UNSIGNED), CAST(RAND(a) * 1000 AS UNSIGNED) 
 
194
FROM t1;
 
195
CAST(RAND(2) * 1000 AS UNSIGNED)        CAST(RAND(a) * 1000 AS UNSIGNED)
 
196
656     405
 
197
122     405
 
198
645     405
 
199
858     656
 
200
354     906
 
201
SELECT CAST(RAND(2) * 1000 AS UNSIGNED), CAST(RAND(a) * 1000 AS UNSIGNED) 
 
202
FROM t1 WHERE a = 1;
 
203
CAST(RAND(2) * 1000 AS UNSIGNED)        CAST(RAND(a) * 1000 AS UNSIGNED)
 
204
656     405
 
205
122     405
 
206
645     405
 
207
PREPARE stmt FROM 
 
208
"SELECT CAST(RAND(2) * 1000 AS UNSIGNED), CAST(RAND(?) * 1000 AS UNSIGNED)
 
209
    FROM t1 WHERE a = 1";
 
210
set @var=2;
 
211
EXECUTE stmt USING @var;
 
212
CAST(RAND(2) * 1000 AS UNSIGNED)        CAST(RAND(?) * 1000 AS UNSIGNED)
 
213
656     656
 
214
122     122
 
215
645     645
 
216
DROP TABLE t1;
 
217
SET timestamp=UNIX_TIMESTAMP('2001-01-01 00:00:00');
 
218
create table t1 (a varchar(90), ts datetime not null, index (a)) engine=innodb default charset=utf8;
 
219
insert into t1 values ('http://www.foo.com/', now());
 
220
select a from t1 where a='http://www.foo.com/' order by abs(timediff(ts, 0));
 
221
a
 
222
http://www.foo.com/
 
223
Warnings:
 
224
Warning 1292    Truncated incorrect time value: '17540424:00:00'
 
225
drop table t1;
 
226
SET timestamp=DEFAULT;
 
227
set sql_mode='traditional';
 
228
select ln(-1);
 
229
ln(-1)
 
230
NULL
 
231
Warnings:
 
232
Warning 1365    Division by 0
 
233
select log10(-1);
 
234
log10(-1)
 
235
NULL
 
236
Warnings:
 
237
Warning 1365    Division by 0
 
238
select log2(-1);
 
239
log2(-1)
 
240
NULL
 
241
Warnings:
 
242
Warning 1365    Division by 0
 
243
select log(2,-1);
 
244
log(2,-1)
 
245
NULL
 
246
Warnings:
 
247
Warning 1365    Division by 0
 
248
select log(-2,1);
 
249
log(-2,1)
 
250
NULL
 
251
Warnings:
 
252
Warning 1365    Division by 0
 
253
set sql_mode='';
 
254
select round(111,-10);
 
255
round(111,-10)
 
256
0
 
257
select round(-5000111000111000155,-1);
 
258
round(-5000111000111000155,-1)
 
259
-5000111000111000160
 
260
select round(15000111000111000155,-1);
 
261
round(15000111000111000155,-1)
 
262
15000111000111000160
 
263
select truncate(-5000111000111000155,-1);
 
264
truncate(-5000111000111000155,-1)
 
265
-5000111000111000150
 
266
select truncate(15000111000111000155,-1);
 
267
truncate(15000111000111000155,-1)
 
268
15000111000111000150
 
269
set names utf8;
 
270
create table t1
 
271
(f1 varchar(32) not null,
 
272
f2 smallint(5) unsigned not null,
 
273
f3 int(10) unsigned not null default '0')
 
274
engine=myisam default charset=utf8;
 
275
insert into t1 values ('zombie',0,0),('gold',1,10000),('silver',2,10000);
 
276
create table t2
 
277
(f1 int(10) unsigned not null,
 
278
f2 int(10) unsigned not null,
 
279
f3 smallint(5) unsigned not null)
 
280
engine=myisam default charset=utf8;
 
281
insert into t2 values (16777216,16787215,1),(33554432,33564431,2);
 
282
select format(t2.f2-t2.f1+1,0) from t1,t2
 
283
where t1.f2 = t2.f3 order by t1.f1;
 
284
format(t2.f2-t2.f1+1,0)
 
285
10,000
 
286
10,000
 
287
drop table t1, t2;
 
288
set names default;
 
289
select cast(-2 as unsigned), 18446744073709551614, -2;
 
290
cast(-2 as unsigned)    18446744073709551614    -2
 
291
18446744073709551614    18446744073709551614    -2
 
292
select abs(cast(-2 as unsigned)), abs(18446744073709551614), abs(-2);
 
293
abs(cast(-2 as unsigned))       abs(18446744073709551614)       abs(-2)
 
294
18446744073709551614    18446744073709551614    2
 
295
select ceiling(cast(-2 as unsigned)), ceiling(18446744073709551614), ceiling(-2);
 
296
ceiling(cast(-2 as unsigned))   ceiling(18446744073709551614)   ceiling(-2)
 
297
18446744073709551614    18446744073709551614    -2
 
298
select floor(cast(-2 as unsigned)), floor(18446744073709551614), floor(-2);
 
299
floor(cast(-2 as unsigned))     floor(18446744073709551614)     floor(-2)
 
300
18446744073709551614    18446744073709551614    -2
 
301
select format(cast(-2 as unsigned), 2), format(18446744073709551614, 2), format(-2, 2);
 
302
format(cast(-2 as unsigned), 2) format(18446744073709551614, 2) format(-2, 2)
 
303
18,446,744,073,709,551,614.00   18,446,744,073,709,551,614.00   -2.00
 
304
select sqrt(cast(-2 as unsigned)), sqrt(18446744073709551614), sqrt(-2);
 
305
sqrt(cast(-2 as unsigned))      sqrt(18446744073709551614)      sqrt(-2)
 
306
4294967296      4294967296      NULL
 
307
select round(cast(-2 as unsigned), 1), round(18446744073709551614, 1), round(-2, 1);
 
308
round(cast(-2 as unsigned), 1)  round(18446744073709551614, 1)  round(-2, 1)
 
309
18446744073709551614    18446744073709551614    -2
 
310
select round(4, cast(-2 as unsigned)), round(4, 18446744073709551614), round(4, -2);
 
311
round(4, cast(-2 as unsigned))  round(4, 18446744073709551614)  round(4, -2)
 
312
4       4       0
 
313
select truncate(cast(-2 as unsigned), 1), truncate(18446744073709551614, 1), truncate(-2, 1);
 
314
truncate(cast(-2 as unsigned), 1)       truncate(18446744073709551614, 1)       truncate(-2, 1)
 
315
18446744073709551614    18446744073709551614    -2
 
316
select truncate(4, cast(-2 as unsigned)), truncate(4, 18446744073709551614), truncate(4, -2);
 
317
truncate(4, cast(-2 as unsigned))       truncate(4, 18446744073709551614)       truncate(4, -2)
 
318
4       4       0
 
319
select round(10000000000000000000, -19), truncate(10000000000000000000, -19);
 
320
round(10000000000000000000, -19)        truncate(10000000000000000000, -19)
 
321
10000000000000000000    10000000000000000000
 
322
select round(1e0, -309), truncate(1e0, -309);
 
323
round(1e0, -309)        truncate(1e0, -309)
 
324
0       0
 
325
select round(1e1,308), truncate(1e1, 308);
 
326
round(1e1,308)  truncate(1e1, 308)
 
327
10      10
 
328
select round(1e1, 2147483648), truncate(1e1, 2147483648);
 
329
round(1e1, 2147483648)  truncate(1e1, 2147483648)
 
330
10      10
 
331
select round(1.1e1, 4294967295), truncate(1.1e1, 4294967295);
 
332
round(1.1e1, 4294967295)        truncate(1.1e1, 4294967295)
 
333
11      11
 
334
select round(1.12e1, 4294967296), truncate(1.12e1, 4294967296);
 
335
round(1.12e1, 4294967296)       truncate(1.12e1, 4294967296)
 
336
11.2    11.2
 
337
select round(1.5, 2147483640), truncate(1.5, 2147483640);
 
338
round(1.5, 2147483640)  truncate(1.5, 2147483640)
 
339
1.500000000000000000000000000000        1.500000000000000000000000000000
 
340
select round(1.5, -2147483649), round(1.5, 2147483648);
 
341
round(1.5, -2147483649) round(1.5, 2147483648)
 
342
0       1.500000000000000000000000000000
 
343
select truncate(1.5, -2147483649), truncate(1.5, 2147483648);
 
344
truncate(1.5, -2147483649)      truncate(1.5, 2147483648)
 
345
0       1.500000000000000000000000000000
 
346
select round(1.5, -4294967296), round(1.5, 4294967296);
 
347
round(1.5, -4294967296) round(1.5, 4294967296)
 
348
0       1.500000000000000000000000000000
 
349
select truncate(1.5, -4294967296), truncate(1.5, 4294967296);
 
350
truncate(1.5, -4294967296)      truncate(1.5, 4294967296)
 
351
0       1.500000000000000000000000000000
 
352
select round(1.5, -9223372036854775808), round(1.5, 9223372036854775808);
 
353
round(1.5, -9223372036854775808)        round(1.5, 9223372036854775808)
 
354
0       1.500000000000000000000000000000
 
355
select truncate(1.5, -9223372036854775808), truncate(1.5, 9223372036854775808);
 
356
truncate(1.5, -9223372036854775808)     truncate(1.5, 9223372036854775808)
 
357
0       1.500000000000000000000000000000
 
358
select round(1.5, 18446744073709551615), truncate(1.5, 18446744073709551615);
 
359
round(1.5, 18446744073709551615)        truncate(1.5, 18446744073709551615)
 
360
1.500000000000000000000000000000        1.500000000000000000000000000000
 
361
select round(18446744073709551614, -1), truncate(18446744073709551614, -1);
 
362
round(18446744073709551614, -1) truncate(18446744073709551614, -1)
 
363
18446744073709551610    18446744073709551610
 
364
select round(4, -4294967200), truncate(4, -4294967200);
 
365
round(4, -4294967200)   truncate(4, -4294967200)
 
366
0       0
 
367
select mod(cast(-2 as unsigned), 3), mod(18446744073709551614, 3), mod(-2, 3);
 
368
mod(cast(-2 as unsigned), 3)    mod(18446744073709551614, 3)    mod(-2, 3)
 
369
2       2       -2
 
370
select mod(5, cast(-2 as unsigned)), mod(5, 18446744073709551614), mod(5, -2);
 
371
mod(5, cast(-2 as unsigned))    mod(5, 18446744073709551614)    mod(5, -2)
 
372
5       5       1
 
373
select pow(cast(-2 as unsigned), 5), pow(18446744073709551614, 5), pow(-2, 5);
 
374
pow(cast(-2 as unsigned), 5)    pow(18446744073709551614, 5)    pow(-2, 5)
 
375
2.13598703592091e96     2.13598703592091e96     -32
 
376
CREATE TABLE t1 (a timestamp, b varchar(20), c bit(1));
 
377
INSERT INTO t1 VALUES('1998-09-23', 'str1', 1), ('2003-03-25', 'str2', 0);
 
378
SELECT a DIV 900 y FROM t1 GROUP BY y;
 
379
y
 
380
22201025555
 
381
22255916666
 
382
SELECT DISTINCT a DIV 900 y FROM t1;
 
383
y
 
384
22201025555
 
385
22255916666
 
386
SELECT b DIV 900 y FROM t1 GROUP BY y;
 
387
y
 
388
0
 
389
Warnings:
 
390
Warning 1366    Incorrect decimal value: '' for column '' at row -1
 
391
Warning 1292    Truncated incorrect DECIMAL value: 'str1'
 
392
Warning 1366    Incorrect decimal value: '' for column '' at row -1
 
393
Warning 1292    Truncated incorrect DECIMAL value: 'str2'
 
394
SELECT c DIV 900 y FROM t1 GROUP BY y;
 
395
y
 
396
0
 
397
DROP TABLE t1;
 
398
CREATE TABLE t1(a LONGBLOB);
 
399
INSERT INTO t1 VALUES('1'),('2'),('3');
 
400
SELECT DISTINCT (a DIV 254576881) FROM t1;
 
401
(a DIV 254576881)
 
402
0
 
403
SELECT (a DIV 254576881) FROM t1 UNION ALL 
 
404
SELECT (a DIV 254576881) FROM t1;
 
405
(a DIV 254576881)
 
406
0
 
407
0
 
408
0
 
409
0
 
410
0
 
411
0
 
412
DROP TABLE t1;
 
413
CREATE TABLE t1(a SET('a','b','c'));
 
414
INSERT INTO t1 VALUES ('a');
 
415
SELECT a DIV 2 FROM t1 UNION SELECT a DIV 2 FROM t1;
 
416
a DIV 2
 
417
0
 
418
DROP TABLE t1;
 
419
CREATE TABLE t1 (a DOUBLE);
 
420
INSERT INTO t1 VALUES (-1.1), (1.1),
 
421
(-1.5), (1.5),
 
422
(-1.9), (1.9),
 
423
(-2.1), (2.1),
 
424
(-2.5), (2.5),
 
425
(-2.9), (2.9),
 
426
# Check numbers with absolute values > 2^53 - 1 
 
427
# (see comments for MAX_EXACT_INTEGER)
 
428
(-1e16 - 0.5), (1e16 + 0.5),
 
429
(-1e16 - 1.5), (1e16 + 1.5);
 
430
SELECT a, ROUND(a) FROM t1;
 
431
a       ROUND(a)
 
432
-1.1    -1
 
433
1.1     1
 
434
-1.5    -2
 
435
1.5     2
 
436
-1.9    -2
 
437
1.9     2
 
438
-2.1    -2
 
439
2.1     2
 
440
-2.5    -2
 
441
2.5     2
 
442
-2.9    -3
 
443
2.9     3
 
444
-1e16   -10000000000000000
 
445
1e16    10000000000000000
 
446
-1.0000000000000002e16  -10000000000000002
 
447
1.0000000000000002e16   10000000000000002
 
448
DROP TABLE t1;
 
449
CREATE TABLE t1(f1 LONGTEXT) engine=myisam;
 
450
INSERT INTO t1 VALUES ('a');
 
451
SELECT 1 FROM (SELECT ROUND(f1) AS a FROM t1) AS s WHERE a LIKE 'a';
 
452
1
 
453
SELECT 1 FROM (SELECT ROUND(f1, f1) AS a FROM t1) AS s WHERE a LIKE 'a';
 
454
1
 
455
DROP TABLE t1;
 
456
End of 5.0 tests
 
457
SELECT 1e308 + 1e308;
 
458
ERROR 22003: DOUBLE value is out of range in '(1e308 + 1e308)'
 
459
SELECT -1e308 - 1e308;
 
460
ERROR 22003: DOUBLE value is out of range in '(-(1e308) - 1e308)'
 
461
SELECT 1e300 * 1e300;
 
462
ERROR 22003: DOUBLE value is out of range in '(1e300 * 1e300)'
 
463
SELECT 1e300 / 1e-300;
 
464
ERROR 22003: DOUBLE value is out of range in '(1e300 / 1e-300)'
 
465
SELECT EXP(750);
 
466
ERROR 22003: DOUBLE value is out of range in 'exp(750)'
 
467
SELECT POW(10, 309);
 
468
ERROR 22003: DOUBLE value is out of range in 'pow(10,309)'
 
469
#
 
470
# Bug #44768: SIGFPE crash when selecting rand from a view
 
471
#             containing null
 
472
#
 
473
CREATE OR REPLACE VIEW v1 AS SELECT NULL AS a;
 
474
SELECT RAND(a) FROM v1;
 
475
RAND(a)
 
476
0.15522042769493574
 
477
DROP VIEW v1;
 
478
SELECT RAND(a) FROM (SELECT NULL AS a) b;
 
479
RAND(a)
 
480
0.15522042769493574
 
481
CREATE TABLE t1 (i INT);
 
482
INSERT INTO t1 VALUES (NULL);
 
483
SELECT RAND(i) FROM t1;
 
484
RAND(i)
 
485
0.15522042769493574
 
486
DROP TABLE t1;
 
487
#
 
488
# Bug#57477 SIGFPE when dividing a huge number a negative number
 
489
#
 
490
SELECT -9999999999999999991 DIV -1;
 
491
ERROR 22003: BIGINT value is out of range in '(-(9999999999999999991) DIV -(1))'
 
492
SELECT -9223372036854775808 DIV -1;
 
493
ERROR 22003: BIGINT value is out of range in '(-(9223372036854775808) DIV -(1))'
 
494
SELECT -9223372036854775808 MOD -1;
 
495
-9223372036854775808 MOD -1
 
496
0
 
497
SELECT -9223372036854775808999 MOD -1;
 
498
-9223372036854775808999 MOD -1
 
499
0
 
500
select 123456789012345678901234567890.123456789012345678901234567890 div 1 as x;
 
501
ERROR 22003: BIGINT value is out of range in '(123456789012345678901234567890.123456789012345678901234567890 DIV 1)'
 
502
select "123456789012345678901234567890.123456789012345678901234567890" div 1 as x;
 
503
ERROR 22003: BIGINT value is out of range in '('123456789012345678901234567890.123456789012345678901234567890' DIV 1)'
 
504
SHOW WARNINGS;
 
505
Level   Code    Message
 
506
Warning 1292    Truncated incorrect DECIMAL value: ''
 
507
Error   1690    BIGINT value is out of range in '('123456789012345678901234567890.123456789012345678901234567890' DIV 1)'
 
508
#
 
509
# Bug#57810 case/when/then : Assertion failed: length || !scale
 
510
#
 
511
SELECT CASE(('')) WHEN (CONVERT(1, CHAR(1))) THEN (('' / 1)) END;
 
512
CASE(('')) WHEN (CONVERT(1, CHAR(1))) THEN (('' / 1)) END
 
513
NULL
 
514
CREATE TABLE t1 SELECT CAST((CASE(('')) WHEN (CONVERT(1, CHAR(1))) THEN (('' / 1)) END) AS CHAR) as C;
 
515
SHOW CREATE TABLE t1;
 
516
Table   Create Table
 
517
t1      CREATE TABLE `t1` (
 
518
  `C` varchar(23) DEFAULT NULL
 
519
) ENGINE=MyISAM DEFAULT CHARSET=latin1
 
520
DROP TABLE t1;
 
521
#
 
522
# Bug#11764994  57900: CREATE TABLE .. SELECT ASSERTS SCALE >= 0 && PRECISION > 0 && SCALE <= PR
 
523
#
 
524
CREATE TABLE t1 SELECT CEIL(LINESTRINGFROMWKB(1) DIV NULL);
 
525
DROP TABLE t1;
 
526
CREATE TABLE t1 SELECT FLOOR(LINESTRINGFROMWKB(1) DIV NULL);
 
527
DROP TABLE t1;
 
528
#
 
529
# Bug#11765923  58937: MANY VALGRIND ERRORS AFTER GROUPING BY RESULT OF DECIMAL COLUMN FUNCTION
 
530
#
 
531
CREATE TABLE t1(f1 DECIMAL(22,1));
 
532
INSERT INTO t1 VALUES (0),(1);
 
533
SELECT ROUND(f1, f1) FROM t1;
 
534
ROUND(f1, f1)
 
535
0.0
 
536
1.0
 
537
SELECT ROUND(f1, f1) FROM t1 GROUP BY 1;
 
538
ROUND(f1, f1)
 
539
0.0
 
540
1.0
 
541
DROP TABLE t1;
 
542
#
 
543
# Bug#11764671  57533: UNINITIALISED VALUES IN COPY_AND_CONVERT (SQL_STRING.CC) WITH CERTAIN CHA
 
544
#
 
545
SELECT ROUND(LEAST(15, -4939092, 0.2704), STDDEV('a'));
 
546
ROUND(LEAST(15, -4939092, 0.2704), STDDEV('a'))
 
547
-4939092.0000
 
548
Warnings:
 
549
Warning 1292    Truncated incorrect DOUBLE value: 'a'
 
550
#
 
551
# Bug#12392636  ASSERTION FAILED: SCALE >= 0 && PRECISION > 0 && SCALE <= PRECISION
 
552
#
 
553
SELECT SUM(DISTINCT (TRUNCATE((.1), NULL)));
 
554
SUM(DISTINCT (TRUNCATE((.1), NULL)))
 
555
NULL
 
556
End of 5.1 tests
 
557
#
 
558
# Bug #8433: Overflow must be an error
 
559
#
 
560
SELECT 1e308 + 1e308;
 
561
ERROR 22003: DOUBLE value is out of range in '(1e308 + 1e308)'
 
562
SELECT -1e308 - 1e308;
 
563
ERROR 22003: DOUBLE value is out of range in '(-(1e308) - 1e308)'
 
564
SELECT 1e300 * 1e300;
 
565
ERROR 22003: DOUBLE value is out of range in '(1e300 * 1e300)'
 
566
SELECT 1e300 / 1e-300;
 
567
ERROR 22003: DOUBLE value is out of range in '(1e300 / 1e-300)'
 
568
SELECT EXP(750);
 
569
ERROR 22003: DOUBLE value is out of range in 'exp(750)'
 
570
SELECT POW(10, 309);
 
571
ERROR 22003: DOUBLE value is out of range in 'pow(10,309)'
 
572
SELECT COT(0);
 
573
ERROR 22003: DOUBLE value is out of range in 'cot(0)'
 
574
SELECT DEGREES(1e307);
 
575
ERROR 22003: DOUBLE value is out of range in 'degrees(1e307)'
 
576
SELECT 9223372036854775808 + 9223372036854775808;
 
577
ERROR 22003: BIGINT UNSIGNED value is out of range in '(9223372036854775808 + 9223372036854775808)'
 
578
SELECT 18446744073709551615 + 1;
 
579
ERROR 22003: BIGINT UNSIGNED value is out of range in '(18446744073709551615 + 1)'
 
580
SELECT 1 + 18446744073709551615;
 
581
ERROR 22003: BIGINT UNSIGNED value is out of range in '(1 + 18446744073709551615)'
 
582
SELECT -2 + CAST(1 AS UNSIGNED);
 
583
ERROR 22003: BIGINT UNSIGNED value is out of range in '(-(2) + cast(1 as unsigned))'
 
584
SELECT CAST(1 AS UNSIGNED) + -2;
 
585
ERROR 22003: BIGINT UNSIGNED value is out of range in '(cast(1 as unsigned) + -(2))'
 
586
SELECT -9223372036854775808 + -9223372036854775808;
 
587
ERROR 22003: BIGINT value is out of range in '(-(9223372036854775808) + -(9223372036854775808))'
 
588
SELECT 9223372036854775807 + 9223372036854775807;
 
589
ERROR 22003: BIGINT value is out of range in '(9223372036854775807 + 9223372036854775807)'
 
590
SELECT CAST(0 AS UNSIGNED) - 9223372036854775809;
 
591
ERROR 22003: BIGINT UNSIGNED value is out of range in '(cast(0 as unsigned) - 9223372036854775809)'
 
592
SELECT 9223372036854775808 - 9223372036854775809;
 
593
ERROR 22003: BIGINT UNSIGNED value is out of range in '(9223372036854775808 - 9223372036854775809)'
 
594
SELECT CAST(1 AS UNSIGNED) - 2;
 
595
ERROR 22003: BIGINT UNSIGNED value is out of range in '(cast(1 as unsigned) - 2)'
 
596
SELECT 18446744073709551615 - (-1);
 
597
ERROR 22003: BIGINT UNSIGNED value is out of range in '(18446744073709551615 - -(1))'
 
598
SELECT -1 - 9223372036854775808;
 
599
ERROR 22003: BIGINT UNSIGNED value is out of range in '(-(1) - 9223372036854775808)'
 
600
SELECT -1 - CAST(1 AS UNSIGNED);
 
601
ERROR 22003: BIGINT UNSIGNED value is out of range in '(-(1) - cast(1 as unsigned))'
 
602
SELECT -9223372036854775808 - 1;
 
603
ERROR 22003: BIGINT value is out of range in '(-(9223372036854775808) - 1)'
 
604
SELECT 9223372036854775807 - -9223372036854775808;
 
605
ERROR 22003: BIGINT value is out of range in '(9223372036854775807 - -(9223372036854775808))'
 
606
set SQL_MODE='NO_UNSIGNED_SUBTRACTION';
 
607
SELECT 18446744073709551615 - 1;
 
608
ERROR 22003: BIGINT value is out of range in '(18446744073709551615 - 1)'
 
609
SELECT 18446744073709551615 - CAST(1 AS UNSIGNED);
 
610
ERROR 22003: BIGINT value is out of range in '(18446744073709551615 - cast(1 as unsigned))'
 
611
SELECT 18446744073709551614 - (-1);
 
612
ERROR 22003: BIGINT value is out of range in '(18446744073709551614 - -(1))'
 
613
SELECT 9223372036854775807 - -1;
 
614
ERROR 22003: BIGINT value is out of range in '(9223372036854775807 - -(1))'
 
615
set SQL_MODE=default;
 
616
SELECT 4294967296 * 4294967296;
 
617
ERROR 22003: BIGINT value is out of range in '(4294967296 * 4294967296)'
 
618
SELECT 9223372036854775808 * 2;
 
619
ERROR 22003: BIGINT UNSIGNED value is out of range in '(9223372036854775808 * 2)'
 
620
SELECT 9223372036854775808 * 2;
 
621
ERROR 22003: BIGINT UNSIGNED value is out of range in '(9223372036854775808 * 2)'
 
622
SELECT 7158278827 * 3221225472;
 
623
ERROR 22003: BIGINT value is out of range in '(7158278827 * 3221225472)'
 
624
SELECT 9223372036854775807 * (-2);
 
625
ERROR 22003: BIGINT value is out of range in '(9223372036854775807 * -(2))'
 
626
SELECT CAST(1 as UNSIGNED) * (-1);
 
627
ERROR 22003: BIGINT UNSIGNED value is out of range in '(cast(1 as unsigned) * -(1))'
 
628
SELECT 9223372036854775807 * 2;
 
629
ERROR 22003: BIGINT value is out of range in '(9223372036854775807 * 2)'
 
630
SELECT ABS(-9223372036854775808);
 
631
ERROR 22003: BIGINT value is out of range in 'abs(-(9223372036854775808))'
 
632
SELECT -9223372036854775808 DIV -1;
 
633
ERROR 22003: BIGINT value is out of range in '(-(9223372036854775808) DIV -(1))'
 
634
SELECT 18446744073709551615 DIV -1;
 
635
ERROR 22003: BIGINT UNSIGNED value is out of range in '(18446744073709551615 DIV -(1))'
 
636
CREATE TABLE t1(a BIGINT, b BIGINT UNSIGNED);
 
637
INSERT INTO t1 VALUES(-9223372036854775808, 9223372036854775809);
 
638
SELECT -a FROM t1;
 
639
ERROR 22003: BIGINT value is out of range in '-('-9223372036854775808')'
 
640
SELECT -b FROM t1;
 
641
ERROR 22003: BIGINT value is out of range in '-('9223372036854775809')'
 
642
DROP TABLE t1;
 
643
SET @a:=999999999999999999999999999999999999999999999999999999999999999999999999999999999;
 
644
SELECT @a + @a;
 
645
ERROR 22003: DECIMAL value is out of range in '((@`a`) + (@`a`))'
 
646
SELECT @a * @a;
 
647
ERROR 22003: DECIMAL value is out of range in '((@`a`) * (@`a`))'
 
648
SELECT -@a - @a;
 
649
ERROR 22003: DECIMAL value is out of range in '(-((@`a`)) - (@`a`))'
 
650
SELECT @a / 0.5;
 
651
ERROR 22003: DECIMAL value is out of range in '((@`a`) / 0.5)'
 
652
SELECT COT(1/0);
 
653
COT(1/0)
 
654
NULL
 
655
SELECT -1 + 9223372036854775808;
 
656
-1 + 9223372036854775808
 
657
9223372036854775807
 
658
SELECT 2 DIV -2;
 
659
2 DIV -2
 
660
-1
 
661
SELECT -(1 DIV 0);
 
662
-(1 DIV 0)
 
663
NULL
 
664
SELECT -9223372036854775808 MOD -1;
 
665
-9223372036854775808 MOD -1
 
666
0
 
667
#
 
668
# Bug #57209 valgrind + Assertion failed: dst > buf 
 
669
#
 
670
SELECT floor(log10(format(concat_ws(5445796E25, 5306463, 30837), -358821)))
 
671
as foo;
 
672
foo
 
673
2
 
674
#
 
675
# Bug #58137 char(0) column cause:
 
676
#            my_gcvt: Assertion `width > 0 && to != ((void *)0)' failed
 
677
#
 
678
CREATE TABLE t1(a char(0));
 
679
INSERT INTO t1 (SELECT -pi());
 
680
Warnings:
 
681
Warning 1265    Data truncated for column 'a' at row 1
 
682
DROP TABLE t1;
 
683
#
 
684
# Bug #59241 invalid memory read
 
685
#            in do_div_mod with doubly assigned variables
 
686
#
 
687
SELECT ((@a:=@b:=1.0) div (@b:=@a:=get_format(datetime, 'usa')));
 
688
((@a:=@b:=1.0) div (@b:=@a:=get_format(datetime, 'usa')))
 
689
NULL
 
690
Warnings:
 
691
Warning 1366    Incorrect decimal value: '' for column '' at row -1
 
692
#
 
693
# Bug #59498 div function broken in mysql-trunk
 
694
#
 
695
SELECT 1 div null;
 
696
1 div null
 
697
NULL
 
698
#
 
699
# Bug #11792200 - DIVIDING LARGE NUMBERS CAUSES STACK CORRUPTIONS
 
700
#
 
701
select (1.175494351E-37 div 1.7976931348623157E+308);
 
702
(1.175494351E-37 div 1.7976931348623157E+308)
 
703
0
 
704
Warnings:
 
705
Warning 1292    Truncated incorrect DECIMAL value: ''
 
706
#
 
707
# Bug#12744991 - DECIMAL_ROUND(X,D) GIVES WRONG RESULTS WHEN D == N*(-9)
 
708
#
 
709
select round(999999999, -9);
 
710
round(999999999, -9)
 
711
1000000000
 
712
select round(999999999.0, -9);
 
713
round(999999999.0, -9)
 
714
1000000000
 
715
select round(999999999999999999, -18);
 
716
round(999999999999999999, -18)
 
717
1000000000000000000
 
718
select round(999999999999999999.0, -18);
 
719
round(999999999999999999.0, -18)
 
720
1000000000000000000
 
721
#
 
722
# Bug#12537160 ASSERTION FAILED:
 
723
# STOP0 <= &TO->BUF[TO->LEN] WITH LARGE NUMBER.
 
724
#
 
725
select 999999999999999999999999999999999999999999999999999999999999999999999999999999999 % 0.1 as foo;
 
726
foo
 
727
0.0
 
728
select 999999999999999999999999999999999999999999999999999999999999999999999999999999999 % 0.0 as foo;
 
729
foo
 
730
NULL
 
731
#
 
732
# Bug#12711164 - 61676:
 
733
# RESULT OF DIV WITH DECIMAL AND INTEGER DOES NOT MAKE SENSE 
 
734
#
 
735
select 5 div 2;
 
736
5 div 2
 
737
2
 
738
select 5.0 div 2.0;
 
739
5.0 div 2.0
 
740
2
 
741
select 5.0 div 2;
 
742
5.0 div 2
 
743
2
 
744
select 5 div 2.0;
 
745
5 div 2.0
 
746
2
 
747
select 5.9 div 2, 1.23456789e3 DIV 2, 1.23456789e9 DIV 2, 1.23456789e19 DIV 2;
 
748
5.9 div 2       1.23456789e3 DIV 2      1.23456789e9 DIV 2      1.23456789e19 DIV 2
 
749
2       617     617283945       6172839450000000000