~linuxjedi/drizzle/trunk-bug-667053

« back to all changes in this revision

Viewing changes to mysql-test/t/type_newdecimal.test

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
--disable_warnings
 
2
drop table if exists t1;
 
3
--enable_warnings
 
4
#
 
5
# constant IN function test
 
6
#
 
7
select 1.1 IN (1.0, 1.2);
 
8
select 1.1 IN (1.0, 1.2, 1.1, 1.4, 0.5);
 
9
select 1.1 IN (1.0, 1.2, NULL, 1.4, 0.5);
 
10
select 0.5 IN (1.0, 1.2, NULL, 1.4, 0.5);
 
11
select 1 IN (1.11, 1.2, 1.1, 1.4, 1, 0.5);
 
12
select 1 IN (1.11, 1.2, 1.1, 1.4, NULL, 0.5);
 
13
 
 
14
#
 
15
# case function test
 
16
#
 
17
select case 1.0 when 0.1 then "a" when 1.0 then "b" else "c" END;
 
18
select case 0.1 when 0.1 then "a" when 1.0 then "b" else "c" END;
 
19
select case 1 when 0.1 then "a" when 1.0 then "b" else "c" END;
 
20
select case 1.0 when 0.1 then "a" when 1 then "b" else "c" END;
 
21
select case 1.001 when 0.1 then "a" when 1 then "b" else "c" END;
 
22
 
 
23
#
 
24
# non constant IN test
 
25
#
 
26
create table t1 (a decimal(6,3));
 
27
insert into t1 values (1.0), (NULL), (0.1);
 
28
select * from t1;
 
29
select 0.1 in (1.0, 1.2, 1.1, a, 1.4, 0.5) from t1;
 
30
drop table t1;
 
31
 
 
32
#
 
33
# if function test
 
34
#
 
35
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);
 
36
select * from t1;
 
37
show create table t1;
 
38
drop table t1;
 
39
 
 
40
#
 
41
# NULLIF
 
42
#
 
43
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);
 
44
select * from t1;
 
45
show create table t1;
 
46
drop table t1;
 
47
 
 
48
#
 
49
# saving in decimal field with overflow
 
50
#
 
51
 
 
52
create table t1 (a decimal(4,2));
 
53
insert into t1 value (10000), (1.1e10), ("11111"), (100000.1);
 
54
insert into t1 value (-10000), (-1.1e10), ("-11111"), (-100000.1);
 
55
select a from t1;
 
56
drop table t1;
 
57
create table t1 (a decimal(4,2) unsigned);
 
58
insert into t1 value (10000), (1.1e10), ("11111"), (100000.1);
 
59
insert into t1 value (-10000), (-1.1e10), ("-11111"), (-100000.1);
 
60
select a from t1;
 
61
drop table t1;
 
62
 
 
63
 
 
64
#
 
65
# saving in field with overflow from decimal
 
66
#
 
67
create table t1 (a bigint);
 
68
insert into t1 values (18446744073709551615.0);
 
69
insert into t1 values (9223372036854775808.0);
 
70
insert into t1 values (-18446744073709551615.0);
 
71
select * from t1;
 
72
drop table t1;
 
73
create table t1 (a bigint unsigned);
 
74
insert into t1 values (18446744073709551615.0);
 
75
insert into t1 values (9223372036854775808.0);
 
76
insert into t1 values (9999999999999999999999999.000);
 
77
insert into t1 values (-1.0);
 
78
select * from t1;
 
79
drop table t1;
 
80
create table t1 (a tinyint);
 
81
insert into t1 values (18446744073709551615.0);
 
82
insert into t1 values (9223372036854775808.0);
 
83
select * from t1;
 
84
drop table t1;
 
85
 
 
86
#
 
87
# test that functions create decimal fields
 
88
#
 
89
create table t1 select round(15.4,-1), truncate(-5678.123451,-3), abs(-1.1), -(-1.1);
 
90
show create table t1;
 
91
drop table t1;
 
92
 
 
93
#
 
94
# Trydy's tests
 
95
#
 
96
set session sql_mode='traditional';
 
97
select 1e10/0e0;
 
98
create table wl1612 (col1 int, col2 decimal(38,10), col3 numeric(38,10));
 
99
insert into wl1612 values(1,12345678901234567890.1234567890,12345678901234567890.1234567890);
 
100
select * from wl1612;
 
101
insert into wl1612 values(2,01234567890123456789.0123456789,01234567890123456789.0123456789);
 
102
select * from wl1612 where col1=2;
 
103
insert into wl1612 values(3,1234567890123456789012345678.0123456789,1234567890123456789012345678.0123456789);
 
104
select * from wl1612 where col1=3;
 
105
 
 
106
select col1/0 from wl1612;
 
107
select col2/0 from wl1612;
 
108
select col3/0 from wl1612;
 
109
 
 
110
insert into wl1612 values(5,5000.0005,5000.0005);
 
111
insert into wl1612 values(6,5000.0005,5000.0005);
 
112
select sum(col2),sum(col3) from wl1612;
 
113
#select avg(col2),avg(col3) from wl1612;
 
114
 
 
115
insert into wl1612 values(7,500000.000005,500000.000005);
 
116
insert into wl1612 values(8,500000.000005,500000.000005);
 
117
select sum(col2),sum(col3) from wl1612 where col1>4;
 
118
#select avg(col2),avg(col3) from wl1612 where col1>4;
 
119
 
 
120
#insert into wl1612 (col1,col2) values(9,123456789012345678901234567890);
 
121
#insert into wl1612 (col1,col3) values(9,123456789012345678901234567890);
 
122
 
 
123
insert into wl1612 (col1, col2) values(9,1.01234567891);
 
124
insert into wl1612 (col1, col2) values(10,1.01234567894);
 
125
insert into wl1612 (col1, col2) values(11,1.01234567895);
 
126
insert into wl1612 (col1, col2) values(12,1.01234567896);
 
127
select col1,col2 from wl1612 where col1>8;
 
128
 
 
129
insert into wl1612 (col1, col3) values(13,1.01234567891);
 
130
insert into wl1612 (col1, col3) values(14,1.01234567894);
 
131
insert into wl1612 (col1, col3) values(15,1.01234567895);
 
132
insert into wl1612 (col1, col3) values(16,1.01234567896);
 
133
select col1,col3 from wl1612 where col1>12;
 
134
 
 
135
select col1 from wl1612 where col1>4 and col2=1.01234567891;
 
136
#-- should return 0 rows
 
137
#
 
138
select col1 from wl1612 where col1>4 and col2=1.0123456789;
 
139
#-- should return col1 values 9 & 10
 
140
#
 
141
select col1 from wl1612 where col1>4 and col2<>1.0123456789;
 
142
#-- should return col1 values 5,6,7,8,11,12
 
143
#
 
144
select col1 from wl1612 where col1>4 and col2<1.0123456789;
 
145
#-- should return 0 rows
 
146
#
 
147
select col1 from wl1612 where col1>4 and col2<=1.0123456789;
 
148
#-- should return col1 values 9 & 10
 
149
#
 
150
select col1 from wl1612 where col1>4 and col2>1.0123456789;
 
151
#-- should return col1 values 5,6,7,8,11,12
 
152
#
 
153
select col1 from wl1612 where col1>4 and col2>=1.0123456789;
 
154
#-- should return col1 values 5,6,7,8,910,11,12
 
155
#
 
156
#select col1, col2 from wl1612 where col1=11 or col1=12;
 
157
select col1 from wl1612 where col1>4 and col2=1.012345679;
 
158
#-- should return col1 values 11,12
 
159
#
 
160
select col1 from wl1612 where col1>4 and col2<>1.012345679;
 
161
#-- should return col1 values 5,6,7,8,9,10
 
162
#
 
163
select col1 from wl1612 where col1>4 and col3=1.01234567891;
 
164
#-- should return 0 rows
 
165
#
 
166
select col1 from wl1612 where col1>4 and col3=1.0123456789;
 
167
#-- should return col1 values 13,14
 
168
#
 
169
select col1 from wl1612 where col1>4 and col3<>1.0123456789;
 
170
#-- should return col1 values 5,6,7,8,15,16
 
171
#
 
172
select col1 from wl1612 where col1>4 and col3<1.0123456789;
 
173
#-- should return 0 rows
 
174
#
 
175
select col1 from wl1612 where col1>4 and col3<=1.0123456789;
 
176
#-- should return col1 values 13,14
 
177
#
 
178
select col1 from wl1612 where col1>4 and col3>1.0123456789;
 
179
#-- should return col1 values 5,6,7,8,15,16
 
180
#
 
181
select col1 from wl1612 where col1>4 and col3>=1.0123456789;
 
182
#-- should return col1 values 5,6,7,8,13,14,15,16
 
183
#
 
184
select col1 from wl1612 where col1>4 and col3=1.012345679;
 
185
#-- should return col1 values 15,16
 
186
#
 
187
select col1 from wl1612 where col1>4 and col3<>1.012345679;
 
188
#-- should return col1 values 5,6,7,8,13,14
 
189
#
 
190
drop table wl1612;
 
191
#
 
192
select 1/3;
 
193
#
 
194
select 0.8=0.7+0.1;
 
195
#-- should return 1 (true)
 
196
#
 
197
select 0.7+0.1;
 
198
#
 
199
create table wl1612_1 (col1 int);
 
200
insert into wl1612_1 values(10);
 
201
#
 
202
select * from wl1612_1 where 0.8=0.7+0.1;
 
203
#--should return 1 row (col1=10)
 
204
#
 
205
select 0.07+0.07 from wl1612_1;
 
206
#
 
207
select 0.07-0.07 from wl1612_1;
 
208
#
 
209
select 0.07*0.07 from wl1612_1;
 
210
#
 
211
select 0.07/0.07 from wl1612_1;
 
212
#
 
213
drop table wl1612_1;
 
214
#
 
215
create table wl1612_2 (col1 decimal(10,2), col2 numeric(10,2));
 
216
insert into wl1612_2 values(1,1);
 
217
insert into wl1612_2 values(+1,+1);
 
218
insert into wl1612_2 values(+01,+01);
 
219
insert into wl1612_2 values(+001,+001);
 
220
#
 
221
select col1,count(*) from wl1612_2 group by col1;
 
222
#
 
223
select col2,count(*) from wl1612_2 group by col2;
 
224
#
 
225
drop table wl1612_2;
 
226
#
 
227
create table wl1612_3 (col1 decimal(10,2), col2 numeric(10,2));
 
228
insert into wl1612_3 values('1','1');
 
229
insert into wl1612_3 values('+1','+1');
 
230
#
 
231
insert into wl1612_3 values('+01','+01');
 
232
insert into wl1612_3 values('+001','+001');
 
233
#
 
234
select col1,count(*) from wl1612_3 group by col1;
 
235
#
 
236
select col2,count(*) from wl1612_3 group by col2;
 
237
#
 
238
drop table wl1612_3;
 
239
#
 
240
select mod(234,10) ;
 
241
#-- should return 4
 
242
#
 
243
select mod(234.567,10.555);
 
244
#-- should return 2.357
 
245
#
 
246
select mod(-234.567,10.555);
 
247
#-- should return -2.357
 
248
#
 
249
select mod(234.567,-10.555);
 
250
#-- should return 2.357
 
251
#
 
252
select round(15.1);
 
253
#-- should return 15
 
254
#
 
255
select round(15.4);
 
256
#-- should return 15
 
257
#
 
258
select round(15.5);
 
259
#-- should return 16
 
260
#
 
261
select round(15.6);
 
262
#-- should return 16
 
263
#
 
264
select round(15.9);
 
265
#-- should return 16
 
266
#
 
267
select round(-15.1);
 
268
#-- should return -15
 
269
#
 
270
select round(-15.4);
 
271
#-- should return -15
 
272
#
 
273
select round(-15.5);
 
274
#-- should return -16
 
275
#
 
276
select round(-15.6);
 
277
#-- should return -16
 
278
#
 
279
select round(-15.9);
 
280
#-- should return -16
 
281
#
 
282
select round(15.1,1);
 
283
#-- should return 15.1
 
284
#
 
285
select round(15.4,1);
 
286
#-- should return 15.4
 
287
#
 
288
select round(15.5,1);
 
289
#-- should return 15.5
 
290
#
 
291
select round(15.6,1);
 
292
#-- should return 15.6
 
293
#
 
294
select round(15.9,1);
 
295
#-- should return 15.9
 
296
#
 
297
select round(-15.1,1);
 
298
#-- should return -15.1
 
299
#
 
300
select round(-15.4,1);
 
301
#-- should return -15.4
 
302
#
 
303
select round(-15.5,1);
 
304
#-- should return -15.5
 
305
#
 
306
select round(-15.6,1);
 
307
#-- should return -15.6
 
308
#
 
309
select round(-15.9,1);
 
310
#-- should return -15.9
 
311
#
 
312
select round(15.1,0);
 
313
#-- should return 15
 
314
#
 
315
select round(15.4,0);
 
316
#-- should return 15
 
317
#
 
318
select round(15.5,0);
 
319
#-- should return 16
 
320
#
 
321
select round(15.6,0);
 
322
#-- should return 16
 
323
#
 
324
select round(15.9,0);
 
325
#-- should return 16
 
326
#
 
327
select round(-15.1,0);
 
328
#-- should return -15
 
329
#
 
330
select round(-15.4,0);
 
331
#-- should return -15
 
332
#
 
333
select round(-15.5,0);
 
334
#-- should return -16
 
335
#
 
336
select round(-15.6,0);
 
337
#-- should return -16
 
338
#
 
339
select round(-15.9,0);
 
340
#-- should return -16
 
341
#
 
342
select round(15.1,-1);
 
343
#-- should return 20
 
344
#
 
345
select round(15.4,-1);
 
346
#-- should return 20
 
347
#
 
348
select round(15.5,-1);
 
349
#-- should return 20
 
350
#
 
351
select round(15.6,-1);
 
352
#-- should return 20
 
353
#
 
354
select round(15.9,-1);
 
355
#-- should return 20
 
356
#
 
357
select round(-15.1,-1);
 
358
#-- should return -20
 
359
#
 
360
select round(-15.4,-1);
 
361
#-- should return -20
 
362
#
 
363
select round(-15.5,-1);
 
364
#-- should return -20
 
365
#
 
366
select round(-15.6,-1);
 
367
#-- should return -20
 
368
#
 
369
select round(-15.91,-1);
 
370
#-- should return -20
 
371
#
 
372
select truncate(5678.123451,0);
 
373
#-- should return 5678
 
374
#
 
375
select truncate(5678.123451,1);
 
376
#-- should return 5678.1
 
377
#
 
378
select truncate(5678.123451,2);
 
379
#-- should return 5678.12
 
380
#
 
381
select truncate(5678.123451,3);
 
382
#-- should return 5678.123
 
383
#
 
384
select truncate(5678.123451,4);
 
385
#-- should return 5678.1234
 
386
#
 
387
select truncate(5678.123451,5);
 
388
#-- should return 5678.12345
 
389
#
 
390
select truncate(5678.123451,6);
 
391
#-- should return 5678.123451
 
392
#
 
393
select truncate(5678.123451,-1);
 
394
#-- should return 5670
 
395
#
 
396
select truncate(5678.123451,-2);
 
397
#-- should return 5600
 
398
#
 
399
select truncate(5678.123451,-3);
 
400
#-- should return 5000
 
401
#
 
402
select truncate(5678.123451,-4);
 
403
#-- should return 0
 
404
#
 
405
select truncate(-5678.123451,0);
 
406
#-- should return -5678
 
407
#
 
408
select truncate(-5678.123451,1);
 
409
#-- should return -5678.1
 
410
#
 
411
select truncate(-5678.123451,2);
 
412
#-- should return -5678.12
 
413
#
 
414
select truncate(-5678.123451,3);
 
415
#-- should return -5678.123
 
416
#
 
417
select truncate(-5678.123451,4);
 
418
#-- should return -5678.1234
 
419
#
 
420
select truncate(-5678.123451,5);
 
421
#-- should return -5678.12345
 
422
#
 
423
select truncate(-5678.123451,6);
 
424
#-- should return -5678.123451
 
425
#
 
426
select truncate(-5678.123451,-1);
 
427
#-- should return -5670
 
428
#
 
429
select truncate(-5678.123451,-2);
 
430
#-- should return -5600
 
431
#
 
432
select truncate(-5678.123451,-3);
 
433
#-- should return -5000
 
434
#
 
435
select truncate(-5678.123451,-4);
 
436
#-- should return 0
 
437
#
 
438
#drop table if exists wl1612_4;
 
439
create table wl1612_4 (col1 int, col2 decimal(30,25), col3 numeric(30,25));
 
440
#
 
441
insert into wl1612_4 values(1,0.0123456789012345678912345,0.0123456789012345678912345);
 
442
#
 
443
select col2/9999999999 from wl1612_4 where col1=1;
 
444
#
 
445
select col3/9999999999 from wl1612_4 where col1=1;
 
446
#
 
447
select 9999999999/col2 from wl1612_4 where col1=1;
 
448
#
 
449
select 9999999999/col3 from wl1612_4 where col1=1;
 
450
#
 
451
select col2*9999999999 from wl1612_4 where col1=1;
 
452
#
 
453
select col3*9999999999 from wl1612_4 where col1=1;
 
454
#
 
455
insert into wl1612_4 values(2,55555.0123456789012345678912345,55555.0123456789012345678912345);
 
456
#
 
457
select col2/9999999999 from wl1612_4 where col1=2;
 
458
#
 
459
select col3/9999999999 from wl1612_4 where col1=2;
 
460
#
 
461
select 9999999999/col2 from wl1612_4 where col1=2;
 
462
#
 
463
select 9999999999/col3 from wl1612_4 where col1=2;
 
464
#
 
465
select col2*9999999999 from wl1612_4 where col1=2;
 
466
#
 
467
select col3*9999999999 from wl1612_4 where col1=2;
 
468
#
 
469
drop table wl1612_4;
 
470
#
 
471
#
 
472
#
 
473
#
 
474
#-- Additional tests for WL#1612 Precision math
 
475
#
 
476
#-- Comparisons should show that a number is
 
477
#-- exactly equal to its value as displayed.
 
478
#
 
479
set sql_mode='';
 
480
#
 
481
select 23.4 + (-41.7), 23.4 - (41.7) = -18.3;
 
482
#
 
483
select -18.3=-18.3;
 
484
#
 
485
select 18.3=18.3;
 
486
#
 
487
select -18.3=18.3;
 
488
#
 
489
select 0.8 = 0.7 + 0.1;
 
490
 
 
491
#
 
492
#-- It should be possible to define a column
 
493
#-- with up to 38 digits precision either before
 
494
#-- or after the decimal point. Any number which
 
495
#-- is inserted, if it's within the range, should
 
496
#-- be exactly the same as the number that gets
 
497
#-- selected.
 
498
#
 
499
drop table if exists t1;
 
500
#
 
501
create table t1 (col1 decimal(38));
 
502
#
 
503
insert into t1 values (12345678901234567890123456789012345678);
 
504
#
 
505
select * from t1;
 
506
#-- should return:
 
507
#+----------------------------------------+
 
508
#| col1                                   |
 
509
#+----------------------------------------+
 
510
#| 12345678901234567890123456789012345678 |
 
511
#+----------------------------------------+
 
512
#
 
513
#drop table t1;
 
514
#
 
515
#create table t1 (col1 decimal(38,38));
 
516
#
 
517
#insert into t1 values (.12345678901234567890123456789012345678);
 
518
#
 
519
#select * from t1;
 
520
#-- should return:
 
521
#+------------------------------------------+
 
522
#| col1                                     |
 
523
#+------------------------------------------+
 
524
#| 0.12345678901234567890123456789012345678 |
 
525
#+------------------------------------------+
 
526
#
 
527
drop table t1;
 
528
#
 
529
create table t1 (col1 decimal(31,30));
 
530
#
 
531
insert into t1 values (0.00000000001);
 
532
#
 
533
select * from t1;
 
534
#-- should return:
 
535
#+---------------+
 
536
#|col1           |
 
537
#+---------------+
 
538
#| 0.00000000001 |
 
539
#+---------------+
 
540
#
 
541
drop table t1;
 
542
#
 
543
#-- The usual arithmetic operators / * + - should work.
 
544
#
 
545
#select 77777777777777777777777777777777777777 / 7777777777777777777777777777777777777 = 10;
 
546
#-- should return 0 (false).
 
547
#
 
548
select 7777777777777777777777777777777777777 * 10;
 
549
#-- should return 77777777777777777777777777777777777770
 
550
#
 
551
select .7777777777777777777777777777777777777 *
 
552
       1000000000000000000;
 
553
#-- should return 777777777777777777.7777777777777777777 
 
554
#
 
555
select .7777777777777777777777777777777777777 - 0.1;
 
556
#-- should return .6777777777777777777777777777777777777 
 
557
#
 
558
select .343434343434343434 + .343434343434343434;
 
559
#-- should return .686868686868686868 
 
560
#
 
561
#-- 5. All arithmetic functions mentioned in the
 
562
#MySQL Reference Manual should work.
 
563
#
 
564
select abs(9999999999999999999999);
 
565
#-- should return 9999999999999999999999
 
566
#
 
567
select abs(-9999999999999999999999);
 
568
#-- should return 9999999999999999999999
 
569
#
 
570
select ceiling(999999999999999999);
 
571
select ceiling(99999999999999999999);
 
572
#-- should return 99999999999999999999
 
573
#
 
574
select ceiling(9.9999999999999999999);
 
575
#-- should return 10
 
576
#
 
577
select ceiling(-9.9999999999999999999);
 
578
#-- should return 9
 
579
#
 
580
select floor(999999999999999999);
 
581
select floor(9999999999999999999999);
 
582
#-- should return 9999999999999999999999
 
583
#
 
584
select floor(9.999999999999999999999);
 
585
#-- should return 9
 
586
#
 
587
select floor(-9.999999999999999999999);
 
588
#-- should return -10
 
589
#
 
590
select floor(-999999999999999999999.999);
 
591
select ceiling(999999999999999999999.999);
 
592
#
 
593
#
 
594
select 99999999999999999999999999999999999999 mod 3;
 
595
#-- should return 0
 
596
#
 
597
select round(99999999999999999.999);
 
598
#-- should return 100000000000000000
 
599
#
 
600
select round(-99999999999999999.999);
 
601
#-- should return -100000000000000000
 
602
#
 
603
select round(99999999999999999.999,3);
 
604
#-- should return 100000000000000000.000
 
605
#
 
606
select round(-99999999999999999.999,3);
 
607
#-- should return -100000000000000000.000
 
608
#
 
609
select truncate(99999999999999999999999999999999999999,31);
 
610
#-- should return 99999999999999999999999999999999999999.000
 
611
#
 
612
select truncate(99.999999999999999999999999999999999999,31);
 
613
#-- should return 99.9999999999999999999999999999999
 
614
#
 
615
select truncate(99999999999999999999999999999999999999,-31);
 
616
# should return 90000000000000000000000000000000
 
617
#
 
618
#-- 6. Set functions (AVG, SUM, COUNT) should work.
 
619
#
 
620
#drop table if exists t1;
 
621
#
 
622
#delimiter //
 
623
#
 
624
#create procedure p1 () begin 
 
625
#  declare v1 int default 1; declare v2 decimal(0,38) default 0; 
 
626
#  create table t1 (col1 decimal(0,38)); 
 
627
#  while v1 <= 10000 do 
 
628
#    insert into t1 values (-v2); 
 
629
#    set v2 = v2 + 0.00000000000000000000000000000000000001; 
 
630
#    set v1 = v1 + 1; 
 
631
#  end while;
 
632
#  select avg(col1),sum(col1),count(col1) from t1; end;//
 
633
#
 
634
#call p1()//
 
635
#-- should return
 
636
#   -- avg(col1)=0.00000000000000000000000000000000000001 added 10,000 times, then divided by 10,000
 
637
#   -- sum(col1)=0.00000000000000000000000000000000000001 added 10,000 times
 
638
#
 
639
#   -- count(col1)=10000
 
640
#
 
641
#delimiter ;//
 
642
#
 
643
#drop procedure p1;
 
644
#drop table t1;
 
645
#
 
646
#-- When I say DECIMAL(x) I should be able to store x digits.
 
647
#-- If I can't, there should be an error at CREATE time.
 
648
#
 
649
#drop table if exists t1;
 
650
#
 
651
#create table t1 (col1 decimal(254));
 
652
#-- should return SQLSTATE 22003 numeric value out of range 
 
653
#
 
654
#-- When I say DECIMAL(x,y) there should be no silent change of precision or
 
655
#-- scale.
 
656
#
 
657
#drop table if exists t1;
 
658
#
 
659
#create table t1 (col1 decimal(0,38));
 
660
#
 
661
#show create table t1;
 
662
#-- should return:
 
663
#+-------+--------------------------------+
 
664
#| Table | Create Table                   |
 
665
#+-------+--------------------------------+
 
666
#| t9    | CREATE TABLE `t1` (            |
 
667
#|`s1` decimal(0,38) default NULL         |
 
668
#| ) ENGINE=MyISAM DEFAULT CHARSET=latin1 |
 
669
#+-------+--------------------------------+
 
670
#
 
671
#drop table t1;
 
672
#
 
673
#-- From WL#1612 "The future" point 2.:
 
674
#-- The standard requires that we treat numbers like "0.5" as
 
675
#-- DECIMAL or NUMERIC, not as floating-point.
 
676
#
 
677
#drop table if exists t1;
 
678
#
 
679
#
 
680
create table t1 as select 0.5;
 
681
#
 
682
show create table t1;
 
683
#-- should return:
 
684
#+-------+-----------------------------------+
 
685
#| Table | Create Table                      |
 
686
#+-------+-----------------------------------+
 
687
#| t7 | CREATE TABLE `t1` (                  |
 
688
#| `0.5` decimal(3,1) NOT NULL default '0.0' |
 
689
#| ) ENGINE=MyISAM DEFAULT CHARSET=latin1    |
 
690
#+-------+-----------------------------------+
 
691
#
 
692
drop table t1;
 
693
#
 
694
#-- From WL#1612, "The future", point 3.: We have to start rounding correctly.
 
695
#
 
696
select round(1.5),round(2.5);
 
697
#-- should return:
 
698
#+------------+------------+
 
699
#| round(1.5) | round(2.5) |
 
700
#+------------+------------+
 
701
#| 2          | 3          |
 
702
#+------------+------------+
 
703
#
 
704
#-- From WL#1612, "The future", point 4.: "select 0.07 * 0.07;" should return 0.0049, not 0.00.
 
705
#-- If operand#1 has scale X and operand#2 has scale Y, then result should have scale (X+Y).
 
706
#
 
707
select 0.07 * 0.07;
 
708
#-- should return 0.0049
 
709
#
 
710
#-- From WL#1612, "The future", point 5.: Division by zero is an error.
 
711
#
 
712
set sql_mode='traditional';
 
713
#
 
714
select 1E-500 = 0;
 
715
#-- should return 1 (true).
 
716
#
 
717
select 1 / 1E-500;
 
718
#
 
719
#-- should return SQLSTATE 22012 division by zero.
 
720
#
 
721
select 1 / 0;
 
722
#-- should return SQLSTATE 22012 division by zero.
 
723
#
 
724
#+-------+
 
725
#| 1 / 0 |
 
726
#+-------+
 
727
#| NULL  |
 
728
#+-------+
 
729
#1 row in set, 1 warning (0.00 sec)
 
730
#
 
731
#-- From WL#1612 "The future" point 6.: Overflow is an error.
 
732
#
 
733
#set sql_mode='';
 
734
#
 
735
#select 1E300 * 1E300;
 
736
#-- should return SQLSTATE 22003 numeric value out of range 
 
737
#
 
738
#select 18446744073709551615 + 1;
 
739
#-- should return SQLSTATE 22003 numeric value out of range 
 
740
#
 
741
#-- 14. From WL#1612 "The future" point 7.:
 
742
#-- If s1 is INTEGER and s2 is DECIMAL, then
 
743
#-- "create table tk7 as select avg(s1),avg(s2) from tk;"
 
744
#-- should not create a table with "double(17,4)" data types.
 
745
#-- The result of AVG must still be exact numeric, with a
 
746
#-- scale the same or greater than the operand's scale.
 
747
#-- The result of SUM must still be exact numeric, with
 
748
#-- a scale the same as the operand's scale.
 
749
#
 
750
#drop table if exists t1;
 
751
#drop table if exists t2;
 
752
#
 
753
#create table t1 (col1 int, col2 decimal(5));
 
754
#
 
755
#create table t2 as select avg(col1),avg(col2) from t1;
 
756
#
 
757
#
 
758
#show create table t2;
 
759
#-- should return:
 
760
#+-------+---------------------------------+
 
761
#| Table | Create Table                    |
 
762
#+-------+---------------------------------+
 
763
#| t2    | CREATE TABLE `t2` (             |
 
764
#| `avg(col1)` decimal(17,4) default NULL, |
 
765
#| `avg(col2)` decimal(17,5) default NULL  |
 
766
#| ) ENGINE=MyISAM DEFAULT CHARSET=latin1  |
 
767
#+-------+---------------------------------+
 
768
#
 
769
#drop table t2;
 
770
#drop table t1;
 
771
#
 
772
#-- From WL#1612 "The future" point 8.: Stop storing leading "+" signs and
 
773
#   leading "0"s.
 
774
#
 
775
#drop table if exists t1;
 
776
#
 
777
#create table t1 (col1 decimal(5,2),col2 decimal(5) zerofill, col3 decimal(3,1));
 
778
#
 
779
#insert into t1 values (1,1,1);
 
780
#
 
781
#select col1 from t1 union select col2 from t1 union select col3 from t1;
 
782
#
 
783
#drop table t1;
 
784
#
 
785
#-- From WL#1612, The future" point 9.:
 
786
#-- Accept the data type and precision and scale as the user
 
787
#-- asks, or return an error, but don't change to something else.
 
788
#
 
789
#drop table if exists t1;
 
790
#
 
791
#create table t1 (col1 numeric(4,2));
 
792
#
 
793
#show create table t1;
 
794
#
 
795
#drop table t1;
 
796
#
 
797
#-- The scripts in the following bugs should work:
 
798
#
 
799
 
 
800
#BUG#559  Maximum precision for DECIMAL column ...
 
801
#BUG#1499 INSERT/UPDATE into decimal field rounding problem
 
802
#BUG#1845 Not correctly recognising value for decimal field
 
803
#BUG#2493 Round function doesn't work correctly
 
804
#BUG#2649 round(0.5) gives 0 (should be 1)
 
805
#BUG#3612 impicite rounding of VARCHARS during aritchmetic operations...
 
806
#BUG#3722 SELECT fails for certain values in Double(255,10) column.
 
807
#BUG#4485 Floating point conversions are inconsistent
 
808
#BUG#4891 MATH
 
809
#BUG#5931 Out-of-range values are accepted
 
810
#BUG#6048 Stored procedure causes operating system reboot
 
811
#BUG#6053 DOUBLE PRECISION literal
 
812
 
 
813
# Tests from 'traditional' mode tests
 
814
#
 
815
set sql_mode='ansi,traditional';
 
816
#
 
817
CREATE TABLE Sow6_2f (col1 NUMERIC(4,2));
 
818
#-- should return OK
 
819
INSERT INTO Sow6_2f VALUES (10.55);
 
820
#-- should return OK
 
821
INSERT INTO Sow6_2f VALUES (10.5555);
 
822
#-- should return OK
 
823
INSERT INTO Sow6_2f VALUES (-10.55);
 
824
#-- should return OK
 
825
INSERT INTO Sow6_2f VALUES (-10.5555);
 
826
#-- should return OK
 
827
INSERT INTO Sow6_2f VALUES (11);
 
828
#-- should return OK
 
829
-- error 1264
 
830
INSERT INTO Sow6_2f VALUES (101.55);
 
831
#-- should return SQLSTATE 22003 numeric value out of range
 
832
-- error 1264
 
833
UPDATE Sow6_2f SET col1 = col1 * 50 WHERE col1 = 11;
 
834
#-- should return SQLSTATE 22003 numeric value out of range
 
835
-- error 1365
 
836
UPDATE Sow6_2f SET col1 = col1 / 0 WHERE col1 > 0;
 
837
#-- should return SQLSTATE 22012 division by zero
 
838
SELECT MOD(col1,0) FROM Sow6_2f;
 
839
#-- should return SQLSTATE 22012 division by zero
 
840
-- error 1366
 
841
INSERT INTO Sow6_2f VALUES ('a59b');
 
842
#-- should return SQLSTATE 22018 invalid character value for cast
 
843
drop table Sow6_2f;
 
844
 
 
845
#
 
846
# bug#9501
 
847
#
 
848
select 10.3330000000000/12.34500000;
 
849
 
 
850
#
 
851
# Bug #10404
 
852
#
 
853
 
 
854
set sql_mode='';
 
855
select 0/0;
 
856
 
 
857
#
 
858
# bug #9546
 
859
#
 
860
--disable_ps_protocol
 
861
select 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 as x;
 
862
select 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 + 1 as x;
 
863
--enable_ps_protocol
 
864
#
 
865
# Bug #10004
 
866
#
 
867
select 0.190287977636363637 + 0.040372670 * 0 -  0;
 
868
#
 
869
# Bug #9527
 
870
#
 
871
select -0.123 * 0;
 
872
 
 
873
#
 
874
# Bug #10232
 
875
#
 
876
 
 
877
CREATE TABLE t1 (f1 DECIMAL (12,9), f2 DECIMAL(2,2));
 
878
INSERT INTO t1 VALUES (10.5, 0);
 
879
UPDATE t1 SET f1 = 4.5;
 
880
SELECT * FROM t1;
 
881
DROP TABLE t1;
 
882
CREATE TABLE t1 (f1 DECIMAL (64,20), f2 DECIMAL(2,2));
 
883
INSERT INTO t1 VALUES (9999999999999999999999999999999999, 0);
 
884
SELECT * FROM t1;
 
885
DROP TABLE t1;
 
886
 
 
887
#
 
888
# Bug #10599: problem with NULL
 
889
#
 
890
 
 
891
select abs(10/0);
 
892
select abs(NULL);
 
893
 
 
894
#
 
895
# Bug #9894 (negative to unsigned column)
 
896
#
 
897
set @@sql_mode='traditional';
 
898
create table t1( d1 decimal(18) unsigned, d2 decimal(20) unsigned, d3 decimal (22) unsigned);
 
899
--error 1264
 
900
insert into t1 values(1,-1,-1);
 
901
drop table t1;
 
902
create table t1 (col1 decimal(5,2), col2 numeric(5,2));
 
903
--error 1264
 
904
insert into t1 values (999.999,999.999);
 
905
--error 1264
 
906
insert into t1 values (-999.999,-999.999);
 
907
select * from t1;
 
908
drop table t1;
 
909
set sql_mode='';
 
910
 
 
911
#
 
912
# Bug #8425 (insufficient precision of the division)
 
913
#
 
914
set @sav_dpi= @@div_precision_increment;
 
915
set @@div_precision_increment=15;
 
916
create table t1 (col1 int, col2 decimal(30,25), col3 numeric(30,25));
 
917
insert into t1 values (1,0.0123456789012345678912345,0.0123456789012345678912345);
 
918
select col2/9999999999 from t1 where col1=1;
 
919
select 9999999999/col2 from t1 where col1=1;
 
920
select 77777777/7777777;
 
921
drop table t1;
 
922
set div_precision_increment= @sav_dpi;
 
923
 
 
924
#
 
925
# Bug #10896 (0.00 > -0.00)
 
926
#
 
927
create table t1 (a decimal(4,2));
 
928
insert into t1 values (0.00);
 
929
select * from t1 where a > -0.00;
 
930
select * from t1 where a = -0.00;
 
931
drop table t1;
 
932
 
 
933
#
 
934
# Bug #11215: a problem with LONGLONG_MIN
 
935
#
 
936
 
 
937
create table t1 (col1 bigint default -9223372036854775808);
 
938
insert into t1 values (default);
 
939
select * from t1;
 
940
drop table t1;
 
941
 
 
942
#
 
943
# Bug #10891 (converting to decimal crashes server)
 
944
#
 
945
select cast('1.00000001335143196001808973960578441619873046875E-10' as decimal(30,15));
 
946
 
 
947
#
 
948
# Bug #11708 (conversion to decimal fails in decimal part)
 
949
#
 
950
select ln(14000) c1, convert(ln(14000),decimal(5,3)) c2, cast(ln(14000) as decimal(5,3)) c3;
 
951
--error 1427
 
952
select convert(ln(14000),decimal(2,3)) c1;
 
953
--error 1427
 
954
select cast(ln(14000) as decimal(2,3)) c1;
 
955
 
 
956
#
 
957
# Bug #8449 (Silent column changes)
 
958
#
 
959
--error 1426
 
960
create table t1 (sl decimal(70,30));
 
961
--error 1425
 
962
create table t1 (sl decimal(32,31));
 
963
--error 1425
 
964
create table t1 (sl decimal(0,38));
 
965
--error 1427
 
966
create table t1 (sl decimal(0,30));
 
967
create table t1 (sl decimal(5, 5));
 
968
show create table t1;
 
969
drop table t1;
 
970
# Test limits
 
971
create table t1 (sl decimal(65, 30));
 
972
show create table t1;
 
973
drop table t1;
 
974
 
 
975
#
 
976
# Bug 11557 (DEFAULT values rounded improperly
 
977
#
 
978
create table t1 (
 
979
       f1 decimal unsigned not null default 17.49, 
 
980
       f2 decimal unsigned not null default 17.68, 
 
981
       f3 decimal unsigned not null default 99.2, 
 
982
       f4 decimal unsigned not null default 99.7, 
 
983
       f5 decimal unsigned not null default 104.49, 
 
984
       f6 decimal unsigned not null default 199.91, 
 
985
       f7 decimal unsigned not null default 999.9, 
 
986
       f8 decimal unsigned not null default 9999.99);
 
987
insert into t1 (f1) values (1);
 
988
select * from t1;
 
989
drop table t1;
 
990
 
 
991
#
 
992
# Bug 12173 (show create table fails)
 
993
#
 
994
create table t1 (
 
995
        f0 decimal (30,30) zerofill not null DEFAULT 0,
 
996
        f1 decimal (0,0) zerofill not null default 0);
 
997
show create table t1;
 
998
drop table t1;
 
999
 
 
1000
#
 
1001
# Bug 12938 (arithmetic loop's zero)
 
1002
#
 
1003
--disable_warnings
 
1004
drop procedure if exists wg2;
 
1005
--enable_warnings
 
1006
delimiter //;
 
1007
create procedure wg2()
 
1008
begin
 
1009
  declare v int default 1;
 
1010
  declare tdec decimal(5) default 0;
 
1011
  while v <= 9 do set tdec =tdec * 10;
 
1012
    select v, tdec;
 
1013
    set v = v + 1;
 
1014
  end while;
 
1015
end//
 
1016
 
 
1017
call wg2()//
 
1018
 
 
1019
delimiter ;//
 
1020
drop procedure wg2;
 
1021
 
 
1022
#
 
1023
# Bug #12979 Stored procedures: crash if inout decimal parameter
 
1024
# (not a SP bug in fact)
 
1025
#
 
1026
 
 
1027
select cast(@non_existing_user_var/2 as DECIMAL);
 
1028
 
 
1029
#
 
1030
# Bug #13667 (Inconsistency for decimal(m,d) specification
 
1031
#
 
1032
--error 1427
 
1033
create table t (d decimal(0,10));
 
1034
 
 
1035
#
 
1036
# Bug #14268 (bad FLOAT->DECIMAL conversion)
 
1037
#
 
1038
 
 
1039
CREATE TABLE t1 (
 
1040
   my_float   FLOAT,
 
1041
   my_double  DOUBLE,
 
1042
   my_varchar VARCHAR(50),
 
1043
   my_decimal DECIMAL(65,30)
 
1044
);
 
1045
SHOW CREATE TABLE t1;
 
1046
 
 
1047
let $max_power= 32;
 
1048
while ($max_power)
 
1049
{
 
1050
   eval INSERT INTO t1 SET my_float = 1.175494345e-$max_power,
 
1051
                           my_double = 1.175494345e-$max_power,
 
1052
                           my_varchar = '1.175494345e-$max_power';
 
1053
   dec $max_power;
 
1054
}
 
1055
SELECT my_float, my_double, my_varchar FROM t1;
 
1056
 
 
1057
# The following statement produces results with garbage past
 
1058
# the significant digits. Improving it is a part of the WL#3977.
 
1059
SELECT CAST(my_float   AS DECIMAL(65,30)), my_float FROM t1;
 
1060
SELECT CAST(my_double  AS DECIMAL(65,30)), my_double FROM t1;
 
1061
SELECT CAST(my_varchar AS DECIMAL(65,30)), my_varchar FROM t1;
 
1062
 
 
1063
# We have to disable warnings here as the test in
 
1064
# Field_new_decimal::store(double):
 
1065
# if (nr2 != nr)
 
1066
# fails randomly depending on compiler options
 
1067
 
 
1068
--disable_warnings
 
1069
UPDATE t1 SET my_decimal = my_float;
 
1070
 
 
1071
# Expected result   0.000000000011754943372854760000
 
1072
# On windows we get 0.000000000011754943372854770000
 
1073
# use replace_result to correct it
 
1074
--replace_result 0.000000000011754943372854770000 0.000000000011754943372854760000
 
1075
SELECT my_decimal, my_float   FROM t1;
 
1076
 
 
1077
UPDATE t1 SET my_decimal = my_double;
 
1078
SELECT my_decimal, my_double  FROM t1;
 
1079
--enable_warnings
 
1080
UPDATE t1 SET my_decimal = my_varchar;
 
1081
SELECT my_decimal, my_varchar FROM t1;
 
1082
 
 
1083
DROP TABLE t1;
 
1084
 
 
1085
#
 
1086
# Bug #13573 (Wrong data inserted for too big values)
 
1087
#
 
1088
 
 
1089
create table t1 (c1 decimal(64));
 
1090
--disable_ps_protocol
 
1091
insert into t1 values(
 
1092
89000000000000000000000000000000000000000000000000000000000000000000000000000000000000000);
 
1093
insert into t1 values(
 
1094
99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 *
 
1095
99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999);
 
1096
--enable_ps_protocol
 
1097
insert into t1 values(1e100);
 
1098
select * from t1;
 
1099
drop table t1;
 
1100
 
 
1101
#
 
1102
# Bug #18014: problem with 'alter table'
 
1103
#
 
1104
 
 
1105
create table t1(a decimal(7,2));
 
1106
insert into t1 values(123.12);
 
1107
select * from t1;
 
1108
alter table t1 modify a decimal(10,2);
 
1109
select * from t1;
 
1110
drop table t1;
 
1111
 
 
1112
#
 
1113
# Bug#19667 group by a decimal expression yields wrong result
 
1114
#
 
1115
create table t1 (i int, j int);
 
1116
insert into t1 values (1,1), (1,2), (2,3), (2,4);
 
1117
select i, count(distinct j) from t1 group by i;
 
1118
select i+0.0 as i2, count(distinct j) from t1 group by i2;
 
1119
drop table t1;
 
1120
 
 
1121
create table t1(f1 decimal(20,6));
 
1122
insert into t1 values (CAST('10:11:12' AS date) + interval 14 microsecond);
 
1123
insert into t1 values (CAST('10:11:12' AS time));
 
1124
select * from t1;
 
1125
drop table t1;
 
1126
 
 
1127
#
 
1128
# Bug #8663 (cant use bigint as input to CAST)
 
1129
#
 
1130
select cast(19999999999999999999 as unsigned);
 
1131
 
 
1132
#
 
1133
# Bug #24558: Increasing decimal column length causes data loss
 
1134
#
 
1135
create table t1(a decimal(18));
 
1136
insert into t1 values(123456789012345678);
 
1137
alter table t1 modify column a decimal(19);
 
1138
select * from t1;
 
1139
drop table t1;
 
1140
 
 
1141
#
 
1142
# Bug #27957 cast as decimal does not check overflow, also inconsistent with group, subselect 
 
1143
#
 
1144
 
 
1145
select cast(11.1234 as DECIMAL(3,2));
 
1146
select * from (select cast(11.1234 as DECIMAL(3,2))) t;
 
1147
 
 
1148
select cast(a as DECIMAL(3,2))
 
1149
 from (select 11.1233 as a
 
1150
  UNION select 11.1234
 
1151
  UNION select 12.1234
 
1152
 ) t;
 
1153
 
 
1154
select cast(a as DECIMAL(3,2)), count(*)
 
1155
 from (select 11.1233 as a
 
1156
  UNION select 11.1234
 
1157
  UNION select 12.1234
 
1158
 ) t group by 1;
 
1159
 
 
1160
#
 
1161
# Bug #28361 Buffer overflow in DECIMAL code on Windows 
 
1162
#
 
1163
 
 
1164
create table t1 (s varchar(100));
 
1165
insert into t1 values (0.00000000010000000000000000364321973154977415791655470655996396089904010295867919921875);
 
1166
drop table t1;
 
1167
 
 
1168
#
 
1169
# Bug #27984 Long Decimal Maths produces truncated results 
 
1170
#
 
1171
 
 
1172
SELECT 1.000000000000 * 99.999999999998 / 100 a,1.000000000000 * (99.999999999998 / 100) b;
 
1173
 
 
1174
#
 
1175
# Bug #29415: CAST AS DECIMAL(P,S) with too big precision/scale 
 
1176
#
 
1177
 
 
1178
SELECT CAST(1 AS decimal(65,10));
 
1179
--error ER_TOO_BIG_PRECISION
 
1180
SELECT CAST(1 AS decimal(66,10));
 
1181
 
 
1182
SELECT CAST(1 AS decimal(65,30));
 
1183
--error ER_TOO_BIG_SCALE
 
1184
SELECT CAST(1 AS decimal(65,31));
 
1185
 
 
1186
CREATE TABLE t1 (a int DEFAULT NULL, b int DEFAULT NULL);
 
1187
INSERT INTO t1 VALUES (3,30), (1,10), (2,10);
 
1188
SELECT a+CAST(1 AS decimal(65,30)) AS aa, SUM(b) FROM t1 GROUP BY aa;
 
1189
--error ER_TOO_BIG_SCALE
 
1190
SELECT a+CAST(1 AS decimal(65,31)) AS aa, SUM(b) FROM t1 GROUP BY aa;
 
1191
 
 
1192
DROP TABLE t1;
 
1193
 
 
1194
#
 
1195
# Bug #29417: assertion abort for a grouping query with decimal user variable
 
1196
#
 
1197
 
 
1198
CREATE TABLE t1 (a int DEFAULT NULL, b int DEFAULT NULL);
 
1199
INSERT INTO t1 VALUES (3,30), (1,10), (2,10);
 
1200
 
 
1201
SET @a= CAST(1 AS decimal);
 
1202
SELECT 1 FROM t1 GROUP BY @b := @a, @b;
 
1203
 
 
1204
DROP TABLE t1;
 
1205
 
 
1206
#
 
1207
# Bug #24907: unpredictable (display) precission, if input precission
 
1208
#             increases
 
1209
#
 
1210
 
 
1211
# As per 10.1.1. Overview of Numeric Types, type (new) DECIMAL has a
 
1212
# maxmimum precision of 30 places after the decimal point. Show that
 
1213
# temp field creation beyond that works and throws a truncation warning.
 
1214
# DECIMAL(37,36) should be adjusted to DECIMAL(31,30).
 
1215
CREATE TABLE t1 SELECT 0.123456789012345678901234567890123456 AS f1;
 
1216
DESC t1;
 
1217
SELECT f1 FROM t1;
 
1218
DROP TABLE t1;
 
1219
 
 
1220
# too many decimal places, AND too many digits altogether (90 = 45+45).
 
1221
# should preserve integers (65 = 45+20)
 
1222
CREATE TABLE t1 SELECT 123451234512345123451234512345123451234512345.678906789067890678906789067890678906789067890 AS f1;
 
1223
DESC t1;
 
1224
SELECT f1 FROM t1;
 
1225
DROP TABLE t1;
 
1226
 
 
1227
--echo End of 5.0 tests
 
1228
 
 
1229
#
 
1230
# Bug#16172 DECIMAL data type processed incorrectly
 
1231
#
 
1232
select cast(143.481 as decimal(4,1));
 
1233
select cast(143.481 as decimal(4,0));
 
1234
select cast(143.481 as decimal(2,1));
 
1235
select cast(-3.4 as decimal(2,1));
 
1236
select cast(99.6 as decimal(2,0));
 
1237
select cast(-13.4 as decimal(2,1));
 
1238
select cast(98.6 as decimal(2,0));