File: type_float.test

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (504 lines) | stat: -rw-r--r-- 14,525 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
# Get default engine value
--let $DEFAULT_ENGINE = `select @@global.default_storage_engine`

# Description
# -----------
# Numeric floating point.

SET sql_mode = 'NO_ENGINE_SUBSTITUTION';
SELECT 10,10.0,10.,.1e+2,100.0e-1;
SELECT 6e-16, -6e-16, --6e-16, -6e-16+1.000000;
SELECT 1e1,1.e1,1.0e1,1e+1,1.e+1,1.0e+1,1e-1,1.e-1,1.0e-1;
SELECT 0.001e+1,0.001e-1, -0.001e+01,-0.001e-01;
SELECT 123.23E+02,-123.23E-02,"123.23E+02"+0.0,"-123.23E-02"+0.0;
SELECT 2147483647E+02,21474836.47E+06;

create table t1 (f1 float(24),f2 float(52));
show full columns from t1;
insert into t1 values(10,10),(1e+5,1e+5),(1234567890,1234567890),(1e+10,1e+10),(1e+15,1e+15),(1e+20,1e+20),(1e+50,1e+50),(1e+150,1e+150);
insert into t1 values(-10,-10),(1e-5,1e-5),(1e-10,1e-10),(1e-15,1e-15),(1e-20,1e-20),(1e-50,1e-50),(1e-150,1e-150);
select * from t1;
drop table t1;

create table t1 (datum double);
insert into t1 values (0.5),(1.0),(1.5),(2.0),(2.5);
select * from t1;
select * from t1 where datum < 1.5;
select * from t1 where datum > 1.5;
select * from t1 where datum = 1.5;
drop table t1;

create table t1 (a  decimal(7,3) not null, key (a));
insert into t1 values ("0"),("-0.00"),("-0.01"),("-0.002"),("1");
select a from t1 order by a;
select min(a) from t1;
drop table t1;

#
# BUG#3612, BUG#4393, BUG#4356, BUG#4394
#

create table t1 (c1 double, c2 varchar(20));
insert t1 values (121,"16");
select c1 + c1 * (c2 / 100) as col from t1;
create table t2 select c1 + c1 * (c2 / 100) as col1, round(c1, 5) as col2, round(c1, 35) as col3, sqrt(c1*1e-15) col4 from t1;
select * from t2;

#Replace default engine value with static engine string 
--replace_result $DEFAULT_ENGINE ENGINE
show create table t2;
drop table t1,t2;

# Bug #1022: When a table contains a 'float' field, 
# and one of the functions MAX, MIN, or AVG is used on that field,
# the system crashes.

create table t1 (a float);
insert into t1 values (1);
select max(a),min(a),avg(a) from t1;
drop table t1;

#
# FLOAT/DOUBLE/DECIMAL handling
#

create table t1 (f float, f2 float(24), f3 float(6,2), d double, d2 float(53), d3 double(10,3), de decimal, de2 decimal(6), de3 decimal(5,2), n numeric, n2 numeric(8), n3 numeric(7,6));
show full columns from t1;
drop table t1;

create table t1 (a  decimal(7,3) not null, key (a));
insert into t1 values ("0"),("-0.00"),("-0.01"),("-0.002"),("1");
select a from t1 order by a;
select min(a) from t1;
drop table t1;

--error 1425
create table t1 (a float(200,100), b double(200,100));

#
# float in a char(1) field
#
create table t1 (c20 char);
insert into t1 values (5000.0);
insert into t1 values (0.5e4);
drop table t1;

# Errors

--error 1063
create table t1 (f float(54));	# Should give an error
--disable_warnings
drop table if exists t1;
--enable_warnings

# Do not allow 'double unsigned' to be set to a negative value (Bug #7700)
create table t1 (d1 double, d2 double unsigned);
insert into t1 set d1 = -1.0;
update t1 set d2 = d1;
select * from t1;
drop table t1;

# Ensure that maximum values as the result of number of decimals
# being specified in table schema are enforced (Bug #7361)
create table t1 (f float(4,3));
insert into t1 values (-11.0),(-11),("-11"),(11.0),(11),("11");
select * from t1;
drop table if exists t1;
create table t1 (f double(4,3));
insert into t1 values (-11.0),(-11),("-11"),(11.0),(11),("11");
select * from t1;
drop table if exists t1;

# Check conversion of floats to character field (Bug #7774)
create table t1 (c char(20));
insert into t1 values (5e-28);
select * from t1;
drop table t1;
create table t1 (c char(6));
insert into t1 values (2e5),(2e6),(2e-4),(2e-5);
select * from t1;
drop table t1;

#
# Bug #13372 (decimal union)
#
create table t1 (d double(10,1));
create table t2 (d double(10,9));
insert into t1 values ("100000000.0");
insert into t2 values ("1.23456780");
create table t3 select * from t2 union select * from t1;
select * from t3;

#Replace default engine value with static engine string 
--replace_result $DEFAULT_ENGINE ENGINE
show create table t3;
drop table t1, t2, t3;


#
# Bug #9855 (inconsistent column type for create select
#
create table t1 select  105213674794682365.00 + 0.0 x;
show warnings;
desc  t1;
drop table t1;

create table t1 select 0.0 x;
desc t1;
create table t2 select 105213674794682365.00 y;
desc t2;
create table t3 select x+y a from t1,t2;
show warnings;
desc t3;
drop table t1,t2,t3;

#
# Bug #22129: A small double precision number becomes zero
#
# check if underflows are detected correctly
select 1e-308, 1.00000001e-300, 100000000e-300;

# check if overflows are detected correctly
select 10e307;

#
# Bug #19690: ORDER BY eliminates rows from the result
#
create table t1(a int, b double(8, 2));
insert into t1 values
(1, 28.50), (1, 121.85), (1, 157.23), (1, 1351.00), (1, -1965.35), (1, 81.75), 
(1, 217.08), (1, 7.94), (4, 96.07), (4, 6404.65), (4, -6500.72), (2, 100.00),
(5, 5.00), (5, -2104.80), (5, 2033.80), (5, 0.07), (5, 65.93),
(3, -4986.24), (3, 5.00), (3, 4857.34), (3, 123.74), (3,  0.16),
(6, -1695.31), (6, 1003.77), (6, 499.72), (6, 191.82);
ANALYZE TABLE t1;
explain select sum(b) s from t1 group by a;
--sorted_result
select sum(b) s from t1 group by a;
--sorted_result
select sum(b) s from t1 group by a having s <> 0;
--sorted_result
select sum(b) s from t1 group by a having s <> 0 order by s;
--sorted_result
select sum(b) s from t1 group by a having s <=> 0;
--sorted_result
select sum(b) s from t1 group by a having s <=> 0 order by s;
alter table t1 add key (a, b);
ANALYZE TABLE t1;
explain select sum(b) s from t1 group by a;
--sorted_result
--skip_if_hypergraph  # Does not use the index, gets different rounding.
select sum(b) s from t1 group by a;
--sorted_result
--skip_if_hypergraph  # Does not use the index, gets different rounding.
select sum(b) s from t1 group by a having s <> 0;
--sorted_result
--skip_if_hypergraph  # Does not use the index, gets different rounding.
select sum(b) s from t1 group by a having s <> 0 order by s;
--sorted_result
--skip_if_hypergraph  # Does not use the index, gets different rounding.
select sum(b) s from t1 group by a having s <=> 0;
--sorted_result
--skip_if_hypergraph  # Does not use the index, gets different rounding.
select sum(b) s from t1 group by a having s <=> 0 order by s;
drop table t1;

--echo End of 4.1 tests

#
# bug #12694 (float(m,d) specifications)
#

--error 1427
create table t1 (s1 float(0,2));
--error 1427
create table t1 (s1 float(1,2));

#
# MySQL Bugs: #11589: mysqltest --ps-protocol, strange output, float/double/real with zerofill
#

CREATE TABLE t1 (
  f1 real zerofill,
  f2 double zerofill,
  f3 float zerofill);
INSERT INTO t1 VALUES ( 0.314152e+1, 0.314152e+1, 0.314152e+1);

let $my_stmt= select f1, f2, f3 FROM t1;
eval PREPARE stmt1 FROM '$my_stmt';
select f1, f2, f3 FROM t1;
eval $my_stmt;
EXECUTE stmt1;

DROP TABLE t1;
# Bug #28121 "INSERT or UPDATE into DOUBLE(200,0) field being truncated to 31 digits"
#

create table t1 (f1 double(200, 0));
insert into t1 values (1e199), (-1e199);
insert into t1 values (1e200), (-1e200);
insert into t1 values (2e200), (-2e200);
select f1 + 0e0 from t1;
drop table t1;

create table t1 (f1 float(30, 0));
insert into t1 values (1e29), (-1e29);
insert into t1 values (1e30), (-1e30);
insert into t1 values (2e30), (-2e30);
select f1 + 0e0 from t1;
drop table t1;

#
# Bug #12860 "Difference in zero padding of exponent between Unix and Windows"
#

create table t1 (c char(6));
insert into t1 values (2e6),(2e-5);
select * from t1;
drop table t1;

#
# Bug #21497 "DOUBLE truncated to unusable value"
#

CREATE TABLE d1 (d DOUBLE);
INSERT INTO d1 VALUES (1.7976931348623157E+308);
SELECT * FROM d1;
--error ER_ILLEGAL_VALUE_FOR_TYPE
INSERT INTO d1 VALUES (1.79769313486232e+308);
SELECT * FROM d1;
DROP TABLE d1;

#
# Bug #26788 "mysqld (debug) aborts when inserting specific numbers into char 
#             fields"
#

create table t1 (a char(20));
insert into t1 values (1.225e-05);
select a+0 from t1;
drop table t1;

# 
# Bug #27483: Casting 'scientific notation type' to 'unsigned bigint' fails on 
#             windows.
#

create table t1(d double, u bigint unsigned);

insert into t1(d) values (9.22337203685479e18),
                         (1.84e19);

update t1 set u = d;
select u from t1;

drop table t1;

#
# Bug #21205: Different number of digits for float/doble/real in --ps-protocol
#

CREATE TABLE t1 (f1 DOUBLE);
INSERT INTO t1 VALUES(-1.79769313486231e+308);
SELECT f1 FROM t1;
DROP TABLE t1;

--echo #
--echo # Bug#12406055 BUFFER OVERFLOW OF VARIABLE 'BUFF' IN STRING::SET_REAL
--echo # 

--echo # Ignoring output from misc. float operations
--disable_result_log

let $nine_65=
99999999999999999999999999999999999999999999999999999999999999999;

select format(-1.7976931348623157E+307,256) as foo;
select least(-1.1111111111111111111111111,
             - group_concat(1.7976931348623157E+308)) as foo;
eval select concat((truncate((-1.7976931348623157E+307),(0x1e))),
                   ($nine_65)) into @a;
--enable_result_log

--echo End of 5.0 tests

--echo #
--echo # Bug#12368853 FORMAT() CRASHES WITH LARGE NUMBERS AFTER TRUNCATE...
--echo #

select format(truncate('1.7976931348623157E+308',-12),1,'fr_BE') as foo;

--echo #
--echo # Bug #13500371 63704: CONVERSION OF '1.' TO A NUMBER GIVES ERROR 1265
--echo # (WARN_DATA_TRUNCATED)
--echo #

CREATE TABLE t1 (f FLOAT);
INSERT INTO t1 VALUES ('1.');
INSERT INTO t1 VALUES ('2.0.');
INSERT INTO t1 VALUES ('.');
SELECT * FROM t1 ORDER BY f;
DROP TABLE t1;
SET sql_mode = default;

--echo #
--echo # Bug#28225635 RUNTIME ERROR: 1E+52 IS OUTSIDE THE RANGE OF
--echo #              REPRESENTABLE VALUES OF TYPE FLOAT
--echo #

CREATE TABLE t5u(c1 FLOAT(58,0) UNSIGNED NOT NULL);
CREATE TABLE t5s(c1 FLOAT(58,0) SIGNED NOT NULL);

--error ER_WARN_DATA_OUT_OF_RANGE
INSERT INTO t5u VALUES('1e+52');
--error ER_WARN_DATA_OUT_OF_RANGE
INSERT INTO t5s VALUES('-1e+52');

SELECT * from t5u;
SELECT * from t5s;

DROP TABLE t5u, t5s;

--echo #
--echo # WL#12575: Deprecate AUTO_INCREMENT on DOUBLE and FLOAT
--echo #

CREATE TABLE t1(a FLOAT PRIMARY KEY AUTO_INCREMENT);
# This statement should not give a warning.
ALTER TABLE t1 ADD COLUMN b INT;
CREATE TABLE t2 LIKE t1;
CREATE TABLE t3(a FLOAT);
ALTER TABLE t3 MODIFY COLUMN a FLOAT PRIMARY KEY AUTO_INCREMENT;
CREATE TABLE t4(a INT PRIMARY KEY);
ALTER TABLE t4 DROP PRIMARY KEY, ADD COLUMN b FLOAT PRIMARY KEY AUTO_INCREMENT;
DROP TABLE t4, t3, t2, t1;

CREATE TABLE t1(a DOUBLE PRIMARY KEY AUTO_INCREMENT);
# This statement should not give a warning.
ALTER TABLE t1 ADD COLUMN b INT;
CREATE TABLE t2 LIKE t1;
CREATE TABLE t3(a DOUBLE);
ALTER TABLE t3 MODIFY COLUMN a DOUBLE PRIMARY KEY AUTO_INCREMENT;
CREATE TABLE t4(a INT PRIMARY KEY);
ALTER TABLE t4 DROP PRIMARY KEY, ADD COLUMN b DOUBLE PRIMARY KEY AUTO_INCREMENT;
DROP TABLE t4, t3, t2, t1;

--echo #
--echo # WL#12595: Deprecate the ability to specify number of digits
--echo #           for floating point types
--echo #

CREATE TABLE t1(a FLOAT(255,0));
# This statement should not give a warning.
ALTER TABLE t1 ADD COLUMN b INT;
CREATE TABLE t2 LIKE t1;
CREATE TABLE t3 AS SELECT * FROM t1;
CREATE TABLE t4(a FLOAT);
ALTER TABLE t4 MODIFY COLUMN a FLOAT(255,0);
CREATE TABLE t5(a INT PRIMARY KEY);
ALTER TABLE t5 ADD COLUMN b FLOAT(255,0);
# This statement should not give a warning.
CREATE TABLE t6(a FLOAT(12)); # Not supported for DOUBLE/REAL
DROP TABLE t6, t5, t4, t3, t2, t1;

CREATE TABLE t1(a DOUBLE(42,12));
# This statement should not give a warning.
ALTER TABLE t1 ADD COLUMN b INT;
CREATE TABLE t2 LIKE t1;
CREATE TABLE t3 AS SELECT * FROM t1;
CREATE TABLE t4(a DOUBLE);
ALTER TABLE t4 MODIFY COLUMN a DOUBLE(42,12);
CREATE TABLE t5(a INT PRIMARY KEY);
ALTER TABLE t5 ADD COLUMN b DOUBLE(42,12);
DROP TABLE t5, t4, t3, t2, t1;

CREATE TABLE t1(a DOUBLE PRECISION(42,12));
# This statement should not give a warning.
ALTER TABLE t1 ADD COLUMN b INT;
CREATE TABLE t2 LIKE t1;
CREATE TABLE t3 AS SELECT * FROM t1;
CREATE TABLE t4(a DOUBLE);
ALTER TABLE t4 MODIFY COLUMN a DOUBLE PRECISION(42,12);
CREATE TABLE t5(a INT PRIMARY KEY);
ALTER TABLE t5 ADD COLUMN b DOUBLE PRECISION(42,12);
DROP TABLE t5, t4, t3, t2, t1;

CREATE TABLE t1(a REAL(42,12));
# This statement should not give a warning.
ALTER TABLE t1 ADD COLUMN b INT;
CREATE TABLE t2 LIKE t1;
CREATE TABLE t3 AS SELECT * FROM t1;
CREATE TABLE t4(a REAL);
ALTER TABLE t4 MODIFY COLUMN a REAL(42,12);
CREATE TABLE t5(a INT PRIMARY KEY);
ALTER TABLE t5 ADD COLUMN b REAL(42,12);
DROP TABLE t5, t4, t3, t2, t1;

CREATE FUNCTION f1(a FLOAT(255,0)) RETURNS DOUBLE(12,3) RETURN 1;
DROP FUNCTION f1;
delimiter ||;
CREATE PROCEDURE p1(IN a FLOAT(255,0), OUT b DOUBLE(12,3))
BEGIN
  SELECT 1 INTO b;
END||
delimiter ;||
DROP PROCEDURE p1;

--echo #
--echo # WL#12391: Deprecate unsigned attribute for DECIMAL and FLOAT data types
--echo #

CREATE TABLE t1(a FLOAT UNSIGNED);
# This statement should not give a warning.
ALTER TABLE t1 ADD COLUMN b INT;
CREATE TABLE t2 LIKE t1;
CREATE TABLE t3 AS SELECT * FROM t1;
CREATE TABLE t4(a FLOAT);
ALTER TABLE t4 MODIFY COLUMN a FLOAT UNSIGNED;
CREATE TABLE t5(a INT PRIMARY KEY);
ALTER TABLE t5 ADD COLUMN b FLOAT UNSIGNED;
DROP TABLE t5, t4, t3, t2, t1;

CREATE TABLE t1(a DOUBLE UNSIGNED);
# This statement should not give a warning.
ALTER TABLE t1 ADD COLUMN b INT;
CREATE TABLE t2 LIKE t1;
CREATE TABLE t3 AS SELECT * FROM t1;
CREATE TABLE t4(a DOUBLE);
ALTER TABLE t4 MODIFY COLUMN a DOUBLE UNSIGNED;
CREATE TABLE t5(a INT PRIMARY KEY);
ALTER TABLE t5 ADD COLUMN b DOUBLE UNSIGNED;
DROP TABLE t5, t4, t3, t2, t1;

CREATE TABLE t1(a REAL UNSIGNED);
# This statement should not give a warning.
ALTER TABLE t1 ADD COLUMN b INT;
CREATE TABLE t2 LIKE t1;
CREATE TABLE t3 AS SELECT * FROM t1;
CREATE TABLE t4(a REAL);
ALTER TABLE t4 MODIFY COLUMN a REAL UNSIGNED;
CREATE TABLE t5(a INT PRIMARY KEY);
ALTER TABLE t5 ADD COLUMN b REAL UNSIGNED;
DROP TABLE t5, t4, t3, t2, t1;

CREATE TABLE t1(a DECIMAL(4,2) UNSIGNED);
# This statement should not give a warning.
ALTER TABLE t1 ADD COLUMN b INT;
CREATE TABLE t2 LIKE t1;
CREATE TABLE t3 AS SELECT * FROM t1;
CREATE TABLE t4(a DECIMAL(4,2));
ALTER TABLE t4 MODIFY COLUMN a DECIMAL(4,2) UNSIGNED;
CREATE TABLE t5(a INT PRIMARY KEY);
ALTER TABLE t5 ADD COLUMN b DECIMAL(4,2) UNSIGNED;
DROP TABLE t5, t4, t3, t2, t1;

CREATE FUNCTION f1(a FLOAT UNSIGNED) RETURNS DOUBLE UNSIGNED RETURN 1;
DROP FUNCTION f1;
delimiter ||;
CREATE PROCEDURE p1(IN a FLOAT UNSIGNED, OUT b DOUBLE UNSIGNED)
BEGIN
  SELECT 1 INTO b;
END||
delimiter ;||
DROP PROCEDURE p1;