1SET TIME_ZONE = _latin1 '+03:00'; 2 3--echo # 4--echo # Start of WL#2649 Number-to-string conversions 5--echo # 6# 7# Basic constants 8# 9select hex(concat(1)); 10create table t1 as select concat(1) as c1; 11show create table t1; 12select hex(c1) from t1; 13drop table t1; 14 15select hex(concat(18446744073709551615)); 16create table t1 as select concat(18446744073709551615) as c1; 17show create table t1; 18select hex(c1) from t1; 19drop table t1; 20 21select hex(concat(1.1)); 22create table t1 as select concat(1.1) as c1; 23show create table t1; 24select hex(c1) from t1; 25drop table t1; 26 27 28# 29# Arithmetic operators 30# 31 32select hex(concat('a', 1+2)), charset(concat(1+2)); 33create table t1 as select concat(1+2) as c1; 34show create table t1; 35drop table t1; 36 37select hex(concat(1-2)); 38create table t1 as select concat(1-2) as c1; 39show create table t1; 40drop table t1; 41 42select hex(concat(1*2)); 43create table t1 as select concat(1*2) as c1; 44show create table t1; 45drop table t1; 46 47select hex(concat(1/2)); 48create table t1 as select concat(1/2) as c1; 49show create table t1; 50drop table t1; 51 52select hex(concat(1 div 2)); 53create table t1 as select concat(1 div 2) as c1; 54show create table t1; 55drop table t1; 56 57select hex(concat(1 % 2)); 58create table t1 as select concat(1 % 2) as c1; 59show create table t1; 60drop table t1; 61 62select hex(concat(-1)); 63create table t1 as select concat(-1) as c1; 64show create table t1; 65drop table t1; 66 67select hex(concat(-(1+2))); 68create table t1 as select concat(-(1+2)) as c1; 69show create table t1; 70drop table t1; 71 72 73# 74# Bit functions 75# 76 77select hex(concat(1|2)); 78create table t1 as select concat(1|2) as c1; 79show create table t1; 80drop table t1; 81 82select hex(concat(1&2)); 83create table t1 as select concat(1&2) as c1; 84show create table t1; 85drop table t1; 86 87select hex(concat(bit_count(12))); 88create table t1 as select concat(bit_count(12)) as c1; 89show create table t1; 90drop table t1; 91 92select hex(concat(2<<1)); 93create table t1 as select concat(2<<1) as c1; 94show create table t1; 95drop table t1; 96 97select hex(concat(2>>1)); 98create table t1 as select concat(2>>1) as c1; 99show create table t1; 100drop table t1; 101 102select hex(concat(~0)); 103create table t1 as select concat(~0) as c1; 104show create table t1; 105drop table t1; 106 107select hex(concat(3^2)); 108create table t1 as select concat(3^2) as c1; 109show create table t1; 110drop table t1; 111 112 113 114# 115# Math functions 116# 117# Note, some tests use LEFT(func(),1) to avoid 118# non-deterministic results on various platforms. 119# 120 121select hex(concat(abs(-2))); 122create table t1 as select concat(abs(-2)) as c1; 123show create table t1; 124drop table t1; 125 126select hex(left(concat(exp(2)),1)); 127create table t1 as select concat(exp(2)) as c1; 128show create table t1; 129drop table t1; 130 131select hex(left(concat(log(2)),1)); 132create table t1 as select concat(log(2)) as c1; 133show create table t1; 134drop table t1; 135 136select hex(left(concat(log2(2)),1)); 137create table t1 as select concat(log2(2)) as c1; 138show create table t1; 139drop table t1; 140 141select hex(left(concat(log10(2)),1)); 142create table t1 as select concat(log10(2)) as c1; 143show create table t1; 144drop table t1; 145 146select hex(left(concat(sqrt(2)),1)); 147create table t1 as select concat(sqrt(2)) as c1; 148show create table t1; 149drop table t1; 150 151select hex(left(concat(pow(2,2)),1)); 152create table t1 as select concat(pow(2,2)) as c1; 153show create table t1; 154drop table t1; 155 156select hex(left(concat(acos(0.5)),1)); 157create table t1 as select concat(acos(0.5)) as c1; 158show create table t1; 159drop table t1; 160 161select hex(left(concat(asin(0.5)),1)); 162create table t1 as select concat(asin(0.5)) as c1; 163show create table t1; 164drop table t1; 165 166select hex(left(concat(atan(0.5)),1)); 167create table t1 as select concat(atan(0.5)) as c1; 168show create table t1; 169drop table t1; 170 171select hex(left(concat(cos(0.5)),1)); 172create table t1 as select concat(cos(0.5)) as c1; 173show create table t1; 174drop table t1; 175 176select hex(left(concat(sin(0.5)),1)); 177create table t1 as select concat(sin(0.5)) as c1; 178show create table t1; 179drop table t1; 180 181select hex(left(concat(tan(0.5)),1)); 182create table t1 as select concat(tan(0.5)) as c1; 183show create table t1; 184drop table t1; 185 186select hex(concat(degrees(0))); 187create table t1 as select concat(degrees(0)) as c1; 188show create table t1; 189drop table t1; 190 191select hex(concat(radians(0))); 192create table t1 as select concat(radians(0)) as c1; 193show create table t1; 194drop table t1; 195 196select hex(concat(ceiling(0.5))); 197create table t1 as select ceiling(0.5) as c0, concat(ceiling(0.5)) as c1; 198show create table t1; 199drop table t1; 200 201select hex(concat(floor(0.5))); 202create table t1 as select floor(0.5) as c0, concat(floor(0.5)) as c1; 203show create table t1; 204drop table t1; 205 206select hex(concat(round(0.5))); 207create table t1 as select concat(round(0.5)) as c1; 208show create table t1; 209drop table t1; 210 211select hex(concat(sign(0.5))); 212create table t1 as select concat(sign(0.5)) as c1; 213show create table t1; 214drop table t1; 215 216create table t1 as select concat(rand()) as c1; 217show create table t1; 218drop table t1; 219 220 221# 222# String functions 223# 224 225select hex(concat(length('a'))); 226create table t1 as select concat(length('a')) as c1; 227show create table t1; 228drop table t1; 229 230select hex(concat(char_length('a'))); 231create table t1 as select concat(char_length('a')) as c1; 232show create table t1; 233drop table t1; 234 235select hex(concat(bit_length('a'))); 236create table t1 as select concat(bit_length('a')) as c1; 237show create table t1; 238drop table t1; 239 240select hex(concat(coercibility('a'))); 241create table t1 as select concat(coercibility('a')) as c1; 242show create table t1; 243drop table t1; 244 245select hex(concat(locate('a','a'))); 246create table t1 as select concat(locate('a','a')) as c1; 247show create table t1; 248drop table t1; 249 250select hex(concat(field('c','a','b','c'))); 251create table t1 as select concat(field('c','a','b','c')) as c1; 252show create table t1; 253drop table t1; 254 255select hex(concat(ascii(61))); 256create table t1 as select concat(ascii(61)) as c1; 257show create table t1; 258drop table t1; 259 260select hex(concat(ord(61))); 261create table t1 as select concat(ord(61)) as c1; 262show create table t1; 263drop table t1; 264 265select hex(concat(find_in_set('b','a,b,c,d'))); 266create table t1 as select concat(find_in_set('b','a,b,c,d')) as c1; 267show create table t1; 268drop table t1; 269 270 271# 272# String hash functions 273# 274 275select md5('a'), hex(md5('a')); 276create table t1 as select md5('a') as c1; 277show create table t1; 278drop table t1; 279 280select old_password('a'), hex(old_password('a')); 281create table t1 as select old_password('a') as c1; 282show create table t1; 283drop table t1; 284 285select password('a'), hex(password('a')); 286create table t1 as select password('a') as c1; 287show create table t1; 288drop table t1; 289 290select sha('a'), hex(sha('a')); 291create table t1 as select sha('a') as c1; 292show create table t1; 293drop table t1; 294 295select sha1('a'), hex(sha1('a')); 296create table t1 as select sha1('a') as c1; 297show create table t1; 298drop table t1; 299 300#select sha2('a',224), hex(sha2('a',224)); 301#create table t1 as select sha2('a',224) as c1; 302#show create table t1; 303#drop table t1; 304 305 306 307# 308# CAST 309# 310 311select hex(concat(cast('-1' as signed))); 312create table t1 as select concat(cast('-1' as signed)) as c1; 313show create table t1; 314drop table t1; 315 316select hex(concat(cast('1' as unsigned))); 317create table t1 as select concat(cast('1' as unsigned)) as c1; 318show create table t1; 319drop table t1; 320 321select hex(concat(cast(1/2 as decimal(5,5)))); 322create table t1 as select concat(cast(1/2 as decimal(5,5))) as c1; 323show create table t1; 324drop table t1; 325 326select hex(concat(cast('2001-01-02 03:04:05' as date))); 327create table t1 as select concat(cast('2001-01-02 03:04:05' as date)) as c1; 328show create table t1; 329select * from t1; 330drop table t1; 331 332select hex(concat(cast('2001-01-02 03:04:05' as time))); 333create table t1 as select concat(cast('2001-01-02 03:04:05' as time)) as c1; 334show create table t1; 335select * from t1; 336drop table t1; 337 338select hex(concat(cast('2001-01-02' as datetime))); 339create table t1 as select concat(cast('2001-01-02' as datetime)) as c1; 340show create table t1; 341select * from t1; 342drop table t1; 343 344 345# 346# Aggregation: LEAST, GREATEST 347# 348select hex(concat(least(1,2))); 349create table t1 as select concat(least(1,2)) as c1; 350show create table t1; 351drop table t1; 352 353select hex(concat(greatest(1,2))); 354create table t1 as select concat(greatest(1,2)) as c1; 355show create table t1; 356drop table t1; 357 358 359# 360# Aggregation: CASE 361# 362select hex(concat(case when 11 then 22 else 33 end)); 363create table t1 as select concat(case when 11 then 22 else 33 end) as c1; 364show create table t1; 365drop table t1; 366 367 368# 369# Aggregation: COALESCE 370# 371select hex(concat(coalesce(1,2))); 372create table t1 as select concat(coalesce(1,2)) as c1; 373show create table t1; 374drop table t1; 375 376 377# 378# Aggregation: CONCAT_WS, GROUP_CONCAT 379# 380select hex(concat_ws(1,2,3)); 381create table t1 as select concat_ws(1,2,3) as c1; 382show create table t1; 383drop table t1; 384 385select hex(group_concat(1,2,3)); 386create table t1 as select group_concat(1,2,3) as c1; 387show create table t1; 388drop table t1; 389 390# 391# Aggregation: UNION 392# 393create table t1 as select 1 as c1 union select 'a'; 394show create table t1; 395select hex(c1) from t1 order by c1; 396drop table t1; 397 398 399# 400# Miscelaneous functions 401# 402 403create table t1 as select concat(last_insert_id()) as c1; 404show create table t1; 405drop table t1; 406 407select hex(concat(benchmark(0,0))); 408create table t1 as select concat(benchmark(0,0)) as c1; 409show create table t1; 410drop table t1; 411 412select hex(concat(sleep(0))); 413create table t1 as select concat(sleep(0)) as c1; 414show create table t1; 415drop table t1; 416 417# Fails with "mtr --ps-protocol" for some reasons. 418#select hex(concat(get_lock('a',0))); 419#select hex(concat(release_lock('a'))); 420#create table t1 as select concat(get_lock('a',0)) as c1; 421#show create table t1; 422#drop table t1; 423 424select hex(concat(is_free_lock('xxxx'))); 425create table t1 as select concat(is_free_lock('xxxx')) as c1; 426show create table t1; 427drop table t1; 428 429create table t1 as select concat(is_used_lock('a')) as c1; 430show create table t1; 431drop table t1; 432 433create table t1 as select concat(release_lock('a')) as c1; 434show create table t1; 435drop table t1; 436 437select hex(concat(crc32(''))); 438create table t1 as select concat(crc32('')) as c1; 439show create table t1; 440drop table t1; 441 442select hex(concat(uncompressed_length(''))); 443create table t1 as select concat(uncompressed_length('')) as c1; 444show create table t1; 445drop table t1; 446 447create table t1 as select concat(connection_id()) as c1; 448show create table t1; 449drop table t1; 450 451select hex(concat(inet_aton('127.1.1.1'))); 452create table t1 as select concat(inet_aton('127.1.1.1')) as c1; 453show create table t1; 454drop table t1; 455 456select hex(concat(inet_ntoa(2130772225))); 457create table t1 as select concat(inet_ntoa(2130772225)) as c1; 458select * from t1; 459show create table t1; 460drop table t1; 461 462# Ensure that row_count() value is reset after drop table. 463select 1; 464select hex(concat(row_count())); 465create table t1 as select concat(row_count()) as c1; 466show create table t1; 467drop table t1; 468 469select hex(concat(found_rows())); 470create table t1 as select concat(found_rows()) as c1; 471show create table t1; 472drop table t1; 473 474create table t1 as select concat(uuid_short()) as c1; 475show create table t1; 476drop table t1; 477 478create table t1 as select concat(uuid()) as c1; 479show create table t1; 480drop table t1; 481 482# 483# Make sure we can mix uuid() to a latin1 object 484# with DERIVATION_IMPLICIT (and higher): 485# (DERIVATION_COERCIBLE + MY_REPERTOIRE_ASCII allow to do so) 486# 487select coercibility(uuid()), coercibility(cast('a' as char character set latin1)); 488select charset(concat(uuid(), cast('a' as char character set latin1))); 489create table t1 as select concat(uuid(), cast('a' as char character set latin1)) as c1; 490show create table t1; 491drop table t1; 492 493create table t1 as select concat(master_pos_wait('non-existent',0,2)) as c1; 494show create table t1; 495drop table t1; 496 497 498# 499# User and system variable functions 500# 501 502# User variables: INT 503select hex(concat(@a1:=1)); 504create table t1 as select concat(@a2:=2) as c1, @a3:=3 as c2; 505select hex(c1) from t1; 506show create table t1; 507drop table t1; 508 509set @a2=1; 510select hex(concat(@a2)); 511create table t1 as select concat(@a2) as c1, @a2 as c2; 512select hex(c1) from t1; 513show create table t1; 514drop table t1; 515 516# User variables: REAL 517select hex(concat(@a1:=sqrt(1))); 518create table t1 as select concat(@a2:=sqrt(1)) as c1, @a3:=sqrt(1) as c2; 519select hex(c1) from t1; 520show create table t1; 521drop table t1; 522 523set @a2=sqrt(1); 524select hex(concat(@a2)); 525create table t1 as select concat(@a2) as c1, @a2 as c2; 526select hex(c1) from t1; 527show create table t1; 528drop table t1; 529 530# User variables: DECIMAL 531select hex(concat(@a1:=1.1)); 532create table t1 as select concat(@a2:=1.1) as c1, @a3:=1.1 as c2; 533select hex(c1) from t1; 534show create table t1; 535drop table t1; 536 537set @a2=1.1; 538select hex(concat(@a2)); 539create table t1 as select concat(@a2) as c1, @a2 as c2; 540select hex(c1) from t1; 541show create table t1; 542drop table t1; 543 544 545select hex(concat(@@ft_max_word_len)); 546create table t1 as select concat(@@ft_max_word_len) as c1; 547select hex(c1) from t1; 548show create table t1; 549drop table t1; 550 551# 552# Comparison functions 553# 554 555select hex(concat('a'='a' IS TRUE)); 556create table t1 as select concat('a'='a' IS TRUE) as c1; 557show create table t1; 558drop table t1; 559 560select hex(concat('a'='a' IS NOT TRUE)); 561create table t1 as select concat('a'='a' IS NOT TRUE) as c1; 562show create table t1; 563drop table t1; 564 565select hex(concat(NOT 'a'='a')); 566create table t1 as select concat(NOT 'a'='a') as c1; 567show create table t1; 568drop table t1; 569 570select hex(concat('a' IS NULL)); 571create table t1 as select concat('a' IS NULL) as c1; 572show create table t1; 573drop table t1; 574 575select hex(concat('a' IS NOT NULL)); 576create table t1 as select concat('a' IS NOT NULL) as c1; 577show create table t1; 578drop table t1; 579 580select hex(concat('a' rlike 'a')); 581create table t1 as select concat('a' IS NOT NULL) as c1; 582show create table t1; 583drop table t1; 584 585select hex(concat(strcmp('a','b'))); 586create table t1 as select concat(strcmp('a','b')) as c1; 587show create table t1; 588drop table t1; 589 590select hex(concat('a' like 'a')); 591create table t1 as select concat('a' like 'b') as c1; 592show create table t1; 593drop table t1; 594 595select hex(concat('a' between 'b' and 'c')); 596create table t1 as select concat('a' between 'b' and 'c') as c1; 597show create table t1; 598drop table t1; 599 600select hex(concat('a' in ('a','b'))); 601create table t1 as select concat('a' in ('a','b')) as c1; 602show create table t1; 603drop table t1; 604 605select hex(concat(interval(23, 1, 15, 17, 30, 44, 200))); 606create table t1 as select concat(interval(23, 1, 15, 17, 30, 44, 200)) as c1; 607show create table t1; 608drop table t1; 609 610create table t1 (a varchar(10), fulltext key(a)); 611insert into t1 values ('a'); 612select hex(concat(match (a) against ('a'))) from t1; 613create table t2 as select concat(match (a) against ('a')) as a from t1; 614show create table t2; 615drop table t1, t2; 616 617select hex(ifnull(1,'a')); 618create table t1 as select ifnull(1,'a') as c1; 619show create table t1; 620drop table t1; 621 622select hex(concat(ifnull(1,1))); 623create table t1 as select concat(ifnull(1,1)) as c1; 624show create table t1; 625drop table t1; 626 627select hex(concat(ifnull(1.1,1.1))); 628create table t1 as select concat(ifnull(1.1,1.1)) as c1; 629show create table t1; 630drop table t1; 631 632select hex(if(1,'b',1)); 633create table t1 as select if(1,'b',1) as c1; 634show create table t1; 635drop table t1; 636 637select hex(if(1,1,'b')); 638create table t1 as select if(1,1,'b') as c1; 639show create table t1; 640drop table t1; 641 642select hex(concat(if(1,1,1))); 643create table t1 as select concat(if(1,1,1)) as c1; 644show create table t1; 645drop table t1; 646 647select hex(concat(nullif(1,2))); 648create table t1 as select concat(nullif(1,2)) as c1; 649show create table t1; 650drop table t1; 651 652# 653# GIS functions 654# 655 656select hex(concat(Dimension(GeomFromText('LINESTRING(0 0,10 10)')))); 657create table t1 as select concat(Dimension(GeomFromText('LINSTRING(0 0,10 10)'))) as c1; 658show create table t1; 659drop table t1; 660 661select hex(concat(NumGeometries(MultiPointFromText('MULTIPOINT(0 0,10 10)')))); 662create table t1 as select concat(NumGeometries(MultiPointFromText('MULTIPOINT(0 0,10 10)'))) as c1; 663show create table t1; 664drop table t1; 665 666select hex(concat(NumPoints(MultiPointFromText('LINESTRING(0 0,10 10)')))); 667create table t1 as select concat(NumPoints(MultiPointFromText('LINESTRING(0 0,10 10)'))) as c1; 668show create table t1; 669drop table t1; 670 671select hex(concat(SRID(MultiPointFromText('MULTIPOINT(0 0,10 10)')))); 672create table t1 as select concat(SRID(MultiPointFromText('MULTIPOINT(0 0,10 10)'))) as c1; 673show create table t1; 674drop table t1; 675 676select hex(concat(NumInteriorRings(PolygonFromText('POLYGON((0 0,50 0,50 50,0 50,0 0), (10 10,20 10,20 20,10 20,10 10))')))); 677create table t1 as select concat(NumInteriorRings(PolygonFromText('POLYGON((0 0,50 0,50 50,0 50,0 0), (10 10,20 10,20 20,10 20,10 10))'))) as c1; 678show create table t1; 679drop table t1; 680 681select hex(concat(IsEmpty(GeomFromText('POINT(1 1)')))); 682create table t1 as select concat(IsEmpty(GeomFromText('Point(1 1)'))) as c1; 683show create table t1; 684drop table t1; 685 686select hex(concat(IsSimple(GeomFromText('POINT(1 1)')))); 687create table t1 as select concat(IsSimple(GeomFromText('Point(1 1)'))) as c1; 688show create table t1; 689drop table t1; 690 691select hex(concat(IsClosed(GeomFromText('LineString(1 1,2 2)')))); 692create table t1 as select concat(IsClosed(GeomFromText('LineString(1 1,2 2)'))) as c1; 693show create table t1; 694drop table t1; 695 696select hex(concat(Equals(GeomFromText('Point(1 1)'),GeomFromText('Point(1 1)')))); 697create table t1 as select concat(Equals(GeomFromText('Point(1 1)'),GeomFromText('Point(1 1)'))) as c1; 698drop table t1; 699 700select hex(concat(x(GeomFromText('Point(1 2)')))); 701create table t1 as select concat(x(GeomFromText('Point(1 2)'))) as c1; 702show create table t1; 703drop table t1; 704 705select hex(concat(y(GeomFromText('Point(1 2)')))); 706create table t1 as select concat(x(GeomFromText('Point(1 2)'))) as c1; 707show create table t1; 708drop table t1; 709 710select hex(concat(GLength(GeomFromText('LineString(1 2,2 2)')))); 711create table t1 as select concat(GLength(GeomFromText('LineString(1 2, 2 2)'))) as c1; 712show create table t1; 713drop table t1; 714 715select hex(concat(Area(GeomFromText('Polygon((0 0,1 0,1 1,0 1,0 0))')))); 716create table t1 as select concat(Area(GeomFromText('Polygon((0 0,1 0,1 1,0 1,0 0))'))) as c1; 717show create table t1; 718drop table t1; 719 720select hex(concat(GeometryType(GeomFromText('Point(1 2)')))); 721create table t1 as select concat(GeometryType(GeomFromText('Point(1 2)'))) as c1; 722show create table t1; 723drop table t1; 724 725select hex(concat(AsText(GeomFromText('Point(1 2)')))); 726create table t1 as select concat(AsText(GeomFromText('Point(1 2)'))) as c1; 727show create table t1; 728drop table t1; 729 730 731 732# 733# Date/Time functions 734# 735 736select hex(concat(period_add(200902, 2))); 737create table t1 as select concat(period_add(200902, 2)) as c1; 738show create table t1; 739drop table t1; 740 741select hex(concat(period_diff(200902, 200802))); 742SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR 743create table t1 as select concat(period_add(200902, 200802)) as c1; 744show create table t1; 745drop table t1; 746 747select hex(concat(to_days(20090224))); 748create table t1 as select concat(to_days(20090224)) as c1; 749show create table t1; 750drop table t1; 751 752select hex(concat(dayofmonth(20090224))); 753create table t1 as select concat(dayofmonth(20090224)) as c1; 754show create table t1; 755drop table t1; 756 757select hex(concat(dayofyear(20090224))); 758create table t1 as select concat(dayofyear(20090224)) as c1; 759show create table t1; 760drop table t1; 761 762select hex(concat(hour('10:11:12'))); 763create table t1 as select concat(hour('10:11:12')) as c1; 764show create table t1; 765drop table t1; 766 767select hex(concat(minute('10:11:12'))); 768create table t1 as select concat(minute('10:11:12')) as c1; 769show create table t1; 770drop table t1; 771 772select hex(concat(second('10:11:12'))); 773create table t1 as select concat(second('10:11:12')) as c1; 774show create table t1; 775drop table t1; 776 777select hex(concat(quarter(20090224))); 778create table t1 as select concat(quarter(20090224)) as c1; 779show create table t1; 780drop table t1; 781 782select hex(concat(week(20090224))); 783create table t1 as select concat(week(20090224)) as c1; 784show create table t1; 785drop table t1; 786 787select hex(concat(yearweek(20090224))); 788create table t1 as select concat(yearweek(20090224)) as c1; 789show create table t1; 790drop table t1; 791 792select hex(concat(year(20090224))); 793create table t1 as select concat(year(20090224)) as c1; 794show create table t1; 795drop table t1; 796 797select hex(concat(weekday(20090224))); 798create table t1 as select concat(weekday(20090224)) as c1; 799show create table t1; 800drop table t1; 801 802select hex(concat(dayofweek(20090224))); 803create table t1 as select concat(dayofweek(20090224)) as c1; 804show create table t1; 805drop table t1; 806 807select hex(concat(unix_timestamp(20090224))); 808create table t1 as select concat(unix_timestamp(20090224)) as c1; 809show create table t1; 810drop table t1; 811 812select hex(concat(time_to_sec('10:11:12'))); 813create table t1 as select concat(time_to_sec('10:11:12')) as c1; 814show create table t1; 815drop table t1; 816 817select hex(concat(extract(year from 20090702))); 818create table t1 as select concat(extract(year from 20090702)) as c1; 819show create table t1; 820drop table t1; 821 822select hex(concat(microsecond('12:00:00.123456'))); 823create table t1 as select concat(microsecond('12:00:00.123456')) as c1; 824show create table t1; 825drop table t1; 826 827select hex(concat(month(20090224))); 828create table t1 as select concat(month(20090224)) as c1; 829show create table t1; 830drop table t1; 831 832 833create table t1 as select concat(last_day('2003-02-05')) as c1; 834show create table t1; 835select c1, hex(c1) from t1; 836drop table t1; 837 838create table t1 as select concat(from_days(730669)) as c1; 839show create table t1; 840select c1, hex(c1) from t1; 841drop table t1; 842 843create table t1 as select concat(curdate()) as c1; 844show create table t1; 845drop table t1; 846 847create table t1 as select concat(utc_date()) as c1; 848show create table t1; 849drop table t1; 850 851create table t1 as select concat(curtime()) as c1; 852show create table t1; 853drop table t1; 854 855create table t1 as select repeat('a',20) as c1 limit 0; 856set timestamp=1216359724; 857insert into t1 values (current_date); 858insert into t1 values (current_time); 859select c1, hex(c1) from t1; 860drop table t1; 861 862create table t1 as select concat(utc_time()) as c1; 863show create table t1; 864drop table t1; 865 866select hex(concat(sec_to_time(2378))); 867create table t1 as select concat(sec_to_time(2378)) as c1; 868show create table t1; 869drop table t1; 870 871select hex(concat(timediff('2001-01-02 00:00:00', '2001-01-01 00:00:00'))); 872create table t1 as select concat(timediff('2001-01-02 00:00:00', '2001-01-01 00:00:00')) as c1; 873show create table t1; 874drop table t1; 875 876select hex(concat(maketime(10,11,12))); 877create table t1 as select concat(maketime(10,11,12)) as c1; 878show create table t1; 879drop table t1; 880 881select hex(get_format(DATE,'USA')); 882create table t1 as select get_format(DATE,'USA') as c1; 883show create table t1; 884drop table t1; 885 886select hex(left(concat(from_unixtime(1111885200)),4)); 887create table t1 as select concat(from_unixtime(1111885200)) as c1; 888show create table t1; 889drop table t1; 890 891select hex(concat(convert_tz('2004-01-01 12:00:00','+10:00','-6:00'))); 892create table t1 as select concat(convert_tz('2004-01-01 12:00:00','+10:00','-6:00')) as c1; 893show create table t1; 894drop table t1; 895 896select hex(concat(date_add('2004-01-01 12:00:00', interval 1 day))); 897create table t1 as select concat(date_add('2004-01-01 12:00:00', interval 1 day)) as c1; 898show create table t1; 899select * from t1; 900drop table t1; 901 902select hex(concat(makedate(2009,1))); 903create table t1 as select concat(makedate(2009,1)) as c1; 904show create table t1; 905select * from t1; 906drop table t1; 907 908create table t1 as select concat(now()) as c1; 909show create table t1; 910drop table t1; 911 912create table t1 as select concat(utc_timestamp()) as c1; 913show create table t1; 914drop table t1; 915 916create table t1 as select concat(sysdate()) as c1; 917show create table t1; 918drop table t1; 919 920select hex(concat(addtime('00:00:00','11:22:33'))); 921create table t1 as select concat(addtime('00:00:00','11:22:33')) as c1; 922show create table t1; 923drop table t1; 924 925select hex(concat(subtime('23:59:59','11:22:33'))); 926create table t1 as select concat(subtime('23:59:59','11:22:33')) as c1; 927show create table t1; 928drop table t1; 929 930 931# 932# Other string functions with numeric input 933# 934select hex(elt(1,2,3)); 935create table t1 as select elt(1,2,3) as c1; 936show create table t1; 937drop table t1; 938 939select hex(export_set(1,2,3,4,2)); 940create table t1 as select export_set(1,2,3,4,2) as c1; 941show create table t1; 942drop table t1; 943 944select hex(insert(1133,3,0,22)); 945create table t1 as select insert(1133,3,0,22) as c1; 946show create table t1; 947drop table t1; 948 949select hex(lcase(123)); 950create table t1 as select lcase(123) as c1; 951show create table t1; 952drop table t1; 953 954select hex(left(123,1)); 955create table t1 as select left(123,1) as c1; 956show create table t1; 957drop table t1; 958 959select hex(lower(123)); 960create table t1 as select lower(123) as c1; 961show create table t1; 962drop table t1; 963 964select hex(lpad(1,2,0)); 965create table t1 as select lpad(1,2,0) as c1; 966show create table t1; 967drop table t1; 968 969select hex(ltrim(1)); 970create table t1 as select ltrim(1) as c1; 971show create table t1; 972drop table t1; 973 974select hex(mid(1,1,1)); 975create table t1 as select mid(1,1,1) as c1; 976show create table t1; 977drop table t1; 978 979select hex(repeat(1,2)); 980create table t1 as select repeat(1,2) as c1; 981show create table t1; 982drop table t1; 983 984select hex(replace(1,1,2)); 985create table t1 as select replace(1,1,2) as c1; 986show create table t1; 987drop table t1; 988 989select hex(reverse(12)); 990create table t1 as select reverse(12) as c1; 991show create table t1; 992drop table t1; 993 994select hex(right(123,1)); 995create table t1 as select right(123,1) as c1; 996show create table t1; 997drop table t1; 998 999select hex(rpad(1,2,0)); 1000create table t1 as select rpad(1,2,0) as c1; 1001show create table t1; 1002drop table t1; 1003 1004select hex(rtrim(1)); 1005create table t1 as select rtrim(1) as c1; 1006show create table t1; 1007drop table t1; 1008 1009select hex(soundex(1)); 1010create table t1 as select soundex(1) as c1; 1011show create table t1; 1012drop table t1; 1013 1014select hex(substring(1,1,1)); 1015create table t1 as select substring(1,1,1) as c1; 1016show create table t1; 1017drop table t1; 1018 1019select hex(trim(1)); 1020create table t1 as select trim(1) as c1; 1021show create table t1; 1022drop table t1; 1023 1024select hex(ucase(1)); 1025create table t1 as select ucase(1) as c1; 1026show create table t1; 1027drop table t1; 1028 1029select hex(upper(1)); 1030create table t1 as select upper(1) as c1; 1031show create table t1; 1032drop table t1; 1033 1034 1035# 1036# Bug#8204 1037# 1038create table t1 as select repeat(' ', 64) as a limit 0; 1039show create table t1; 1040insert into t1 values ("1.1"), ("2.1"); 1041select a, hex(a) from t1; 1042update t1 set a= a + 0.1; 1043select a, hex(a) from t1; 1044drop table t1; 1045 1046 1047# 1048# Columns 1049# 1050create table t1 (a tinyint); 1051insert into t1 values (1); 1052select hex(concat(a)) from t1; 1053create table t2 as select concat(a) from t1; 1054show create table t2; 1055drop table t1, t2; 1056 1057create table t1 (a tinyint zerofill); 1058insert into t1 values (1), (10), (100); 1059select hex(concat(a)), a from t1; 1060drop table t1; 1061 1062create table t1 (a tinyint(4) zerofill); 1063insert into t1 values (1), (10), (100); 1064select hex(concat(a)), a from t1; 1065drop table t1; 1066 1067create table t1 (a decimal(10,2)); 1068insert into t1 values (123.45); 1069select hex(concat(a)) from t1; 1070create table t2 as select concat(a) from t1; 1071show create table t2; 1072drop table t1, t2; 1073 1074create table t1 (a smallint); 1075insert into t1 values (1); 1076select hex(concat(a)) from t1; 1077create table t2 as select concat(a) from t1; 1078show create table t2; 1079drop table t1, t2; 1080 1081create table t1 (a smallint zerofill); 1082insert into t1 values (1), (10), (100), (1000), (10000); 1083select hex(concat(a)), a from t1; 1084drop table t1; 1085 1086create table t1 (a mediumint); 1087insert into t1 values (1); 1088select hex(concat(a)) from t1; 1089create table t2 as select concat(a) from t1; 1090show create table t2; 1091drop table t1, t2; 1092 1093create table t1 (a mediumint zerofill); 1094insert into t1 values (1), (10), (100), (1000), (10000); 1095select hex(concat(a)), a from t1; 1096drop table t1; 1097 1098create table t1 (a int); 1099insert into t1 values (1); 1100select hex(concat(a)) from t1; 1101create table t2 as select concat(a) from t1; 1102show create table t2; 1103drop table t1, t2; 1104 1105create table t1 (a int zerofill); 1106insert into t1 values (1), (10), (100), (1000), (10000); 1107select hex(concat(a)), a from t1; 1108drop table t1; 1109 1110create table t1 (a bigint); 1111insert into t1 values (1); 1112select hex(concat(a)) from t1; 1113create table t2 as select concat(a) from t1; 1114show create table t2; 1115drop table t1, t2; 1116 1117create table t1 (a bigint zerofill); 1118insert into t1 values (1), (10), (100), (1000), (10000); 1119select hex(concat(a)), a from t1; 1120drop table t1; 1121 1122create table t1 (a float); 1123insert into t1 values (123.456); 1124select hex(concat(a)) from t1; 1125select concat(a) from t1; 1126create table t2 as select concat(a) from t1; 1127show create table t2; 1128drop table t1, t2; 1129 1130create table t1 (a float zerofill); 1131insert into t1 values (1.1), (10.1), (100.1), (1000.1), (10000.1); 1132select hex(concat(a)), a from t1; 1133drop table t1; 1134 1135create table t1 (a double); 1136insert into t1 values (123.456); 1137select hex(concat(a)) from t1; 1138select concat(a) from t1; 1139create table t2 as select concat(a) from t1; 1140show create table t2; 1141drop table t1, t2; 1142 1143create table t1 (a double zerofill); 1144insert into t1 values (1.1), (10.1), (100.1), (1000.1), (10000.1); 1145select hex(concat(a)), a from t1; 1146drop table t1; 1147 1148create table t1 (a year(2)); 1149insert into t1 values (1); 1150select hex(concat(a)) from t1; 1151create table t2 as select concat(a) from t1; 1152show create table t2; 1153drop table t1, t2; 1154 1155create table t1 (a year); 1156insert into t1 values (1); 1157select hex(concat(a)) from t1; 1158create table t2 as select concat(a) from t1; 1159show create table t2; 1160drop table t1, t2; 1161 1162create table t1 (a bit(64)); 1163# BIT is always BINARY 1164insert into t1 values (1); 1165select hex(concat(a)) from t1; 1166create table t2 as select concat(a) from t1; 1167show create table t2; 1168drop table t1, t2; 1169 1170create table t1 (a timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP); 1171insert into t1 values (0); 1172insert into t1 values (20010203040506); 1173insert into t1 values (19800203040506); 1174insert into t1 values ('2001-02-03 04:05:06'); 1175select hex(concat(a)) from t1; 1176select concat(a) from t1; 1177create table t2 as select concat(a) from t1; 1178show create table t2; 1179drop table t1, t2; 1180 1181create table t1 (a date); 1182insert into t1 values ('2001-02-03'); 1183insert into t1 values (20010203); 1184select hex(concat(a)) from t1; 1185create table t2 as select concat(a) from t1; 1186show create table t2; 1187drop table t1, t2; 1188 1189create table t1 (a time); 1190insert into t1 values (1); 1191insert into t1 values ('01:02:03'); 1192select hex(concat(a)) from t1; 1193select concat(a) from t1; 1194create table t2 as select concat(a) from t1; 1195show create table t2; 1196drop table t1, t2; 1197 1198create table t1 (a datetime); 1199insert into t1 values ('2001-02-03 04:05:06'); 1200insert into t1 values (20010203040506); 1201select hex(concat(a)) from t1; 1202create table t2 as select concat(a) from t1; 1203show create table t2; 1204drop table t1, t2; 1205 1206 1207# 1208# create view with string functions with numeric input 1209# 1210# Switched off in ucs tests due to bug#50716 1211if ($not_ucs) 1212{ 1213create view v1 as select concat(1,2,3) as c1; 1214show columns from v1; 1215select hex(c1) from v1; 1216drop view v1; 1217 1218create view v1 as select concat_ws(',',1,2,3) as c1; 1219show columns from v1; 1220select hex(c1) from v1; 1221drop view v1; 1222 1223create view v1 as select elt(1,2,3) as c1; 1224show columns from v1; 1225select hex(c1) from v1; 1226drop view v1; 1227 1228create view v1 as select export_set(1,2,3,4,2) as c1; 1229show columns from v1; 1230select hex(c1) from v1; 1231drop view v1; 1232 1233create view v1 as select insert(1133,3,0,22) as c1; 1234show columns from v1; 1235select hex(c1) from v1; 1236drop view v1; 1237 1238create view v1 as select lcase(123) as c1; 1239show columns from v1; 1240select hex(c1) from v1; 1241drop view v1; 1242 1243create view v1 as select left(123,1) as c1; 1244show columns from v1; 1245select hex(c1) from v1; 1246drop view v1; 1247 1248create view v1 as select lower(123) as c1; 1249show columns from v1; 1250select hex(c1) from v1; 1251drop view v1; 1252 1253create view v1 as select lpad(1,2,0) as c1; 1254show columns from v1; 1255select hex(c1) from v1; 1256drop view v1; 1257 1258create view v1 as select ltrim(1) as c1; 1259show columns from v1; 1260select hex(c1) from v1; 1261drop view v1; 1262 1263create view v1 as select mid(1,1,1) as c1; 1264show columns from v1; 1265select hex(c1) from v1; 1266drop view v1; 1267 1268create view v1 as select repeat(1,2) as c1; 1269show columns from v1; 1270select hex(c1) from v1; 1271drop view v1; 1272 1273create view v1 as select replace(1,1,2) as c1; 1274show columns from v1; 1275select hex(c1) from v1; 1276drop view v1; 1277 1278create view v1 as select reverse(12) as c1; 1279show columns from v1; 1280select hex(c1) from v1; 1281drop view v1; 1282 1283create view v1 as select right(123,1) as c1; 1284show columns from v1; 1285select hex(c1) from v1; 1286drop view v1; 1287 1288create view v1 as select rpad(1,2,0) as c1; 1289show columns from v1; 1290select hex(c1) from v1; 1291drop view v1; 1292 1293create view v1 as select rtrim(1) as c1; 1294show columns from v1; 1295select hex(c1) from v1; 1296drop view v1; 1297 1298create view v1 as select soundex(1) as c1; 1299show columns from v1; 1300select hex(c1) from v1; 1301drop view v1; 1302 1303create view v1 as select substring(1,1,1) as c1; 1304show columns from v1; 1305select hex(c1) from v1; 1306drop view v1; 1307 1308create view v1 as select trim(1) as c1; 1309show columns from v1; 1310select hex(c1) from v1; 1311drop view v1; 1312 1313create view v1 as select ucase(1) as c1; 1314show columns from v1; 1315select hex(c1) from v1; 1316drop view v1; 1317 1318create view v1 as select upper(1) as c1; 1319show columns from v1; 1320select hex(c1) from v1; 1321drop view v1; 1322} 1323 1324 1325# 1326# Views from tables with numeric columns 1327# 1328create table t1 (a tinyint); 1329insert into t1 values (1); 1330create view v1(a) as select concat(a) from t1; 1331show columns from v1; 1332select hex(a) from v1; 1333drop table t1; 1334drop view v1; 1335 1336create table t1 (a tinyint zerofill); 1337insert into t1 values (1), (10), (100); 1338create view v1(a) as select concat(a) from t1; 1339show columns from v1; 1340select hex(a) from v1; 1341drop table t1; 1342drop view v1; 1343 1344create table t1 (a tinyint(30) zerofill); 1345insert into t1 values (1), (10), (100); 1346create view v1(a) as select concat(a) from t1; 1347show columns from v1; 1348select hex(a) from v1; 1349drop table t1; 1350drop view v1; 1351 1352create table t1 (a decimal(10,2)); 1353insert into t1 values (123.45); 1354create view v1(a) as select concat(a) from t1; 1355show columns from v1; 1356select hex(a) from v1; 1357drop table t1; 1358drop view v1; 1359 1360create table t1 (a smallint); 1361insert into t1 values (1); 1362create view v1(a) as select concat(a) from t1; 1363show columns from v1; 1364select hex(a) from v1; 1365drop table t1; 1366drop view v1; 1367 1368create table t1 (a smallint zerofill); 1369insert into t1 values (1), (10), (100), (1000), (10000); 1370create view v1(a) as select concat(a) from t1; 1371show columns from v1; 1372select hex(a) from v1; 1373drop table t1; 1374drop view v1; 1375 1376create table t1 (a mediumint); 1377insert into t1 values (1); 1378create view v1(a) as select concat(a) from t1; 1379show columns from v1; 1380select hex(a) from v1; 1381drop table t1; 1382drop view v1; 1383 1384create table t1 (a mediumint zerofill); 1385insert into t1 values (1), (10), (100), (1000), (10000); 1386create view v1(a) as select concat(a) from t1; 1387show columns from v1; 1388select hex(a) from v1; 1389drop table t1; 1390drop view v1; 1391 1392create table t1 (a int); 1393insert into t1 values (1); 1394create view v1(a) as select concat(a) from t1; 1395show columns from v1; 1396select hex(a) from v1; 1397drop table t1; 1398drop view v1; 1399 1400create table t1 (a int zerofill); 1401insert into t1 values (1), (10), (100), (1000), (10000); 1402create view v1(a) as select concat(a) from t1; 1403show columns from v1; 1404select hex(a) from v1; 1405drop table t1; 1406drop view v1; 1407 1408create table t1 (a bigint); 1409insert into t1 values (1); 1410create view v1(a) as select concat(a) from t1; 1411show columns from v1; 1412select hex(a) from v1; 1413drop table t1; 1414drop view v1; 1415 1416create table t1 (a bigint zerofill); 1417insert into t1 values (1), (10), (100), (1000), (10000); 1418create view v1(a) as select concat(a) from t1; 1419show columns from v1; 1420select hex(a) from v1; 1421drop table t1; 1422drop view v1; 1423 1424create table t1 (a float); 1425insert into t1 values (123.456); 1426create view v1(a) as select concat(a) from t1; 1427show columns from v1; 1428select hex(a) from v1; 1429drop table t1; 1430drop view v1; 1431 1432create table t1 (a float zerofill); 1433insert into t1 values (1.1), (10.1), (100.1), (1000.1), (10000.1); 1434create view v1(a) as select concat(a) from t1; 1435show columns from v1; 1436select hex(a) from v1; 1437drop table t1; 1438drop view v1; 1439 1440create table t1 (a double); 1441insert into t1 values (123.456); 1442select concat(a) from t1; 1443create view v1(a) as select concat(a) from t1; 1444show columns from v1; 1445select hex(a) from v1; 1446drop table t1; 1447drop view v1; 1448 1449create table t1 (a double zerofill); 1450insert into t1 values (1.1), (10.1), (100.1), (1000.1), (10000.1); 1451create view v1(a) as select concat(a) from t1; 1452show columns from v1; 1453select hex(a) from v1; 1454drop table t1; 1455drop view v1; 1456 1457create table t1 (a year(2)); 1458insert into t1 values (1); 1459create view v1(a) as select concat(a) from t1; 1460show columns from v1; 1461select hex(a) from v1; 1462drop table t1; 1463drop view v1; 1464 1465create table t1 (a year); 1466insert into t1 values (1); 1467create view v1(a) as select concat(a) from t1; 1468show columns from v1; 1469select hex(a) from v1; 1470drop table t1; 1471drop view v1; 1472 1473create table t1 (a bit(64)); 1474# BIT is always BINARY 1475insert into t1 values (1); 1476create view v1(a) as select concat(a) from t1; 1477show columns from v1; 1478select hex(a) from v1; 1479drop table t1; 1480drop view v1; 1481 1482create table t1 (a timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP); 1483insert into t1 values (0); 1484insert into t1 values (20010203040506); 1485insert into t1 values (19800203040506); 1486insert into t1 values ('2001-02-03 04:05:06'); 1487create view v1(a) as select concat(a) from t1; 1488show columns from v1; 1489select hex(a) from v1; 1490drop table t1; 1491drop view v1; 1492 1493create table t1 (a date); 1494insert into t1 values ('2001-02-03'); 1495insert into t1 values (20010203); 1496create view v1(a) as select concat(a) from t1; 1497show columns from v1; 1498select hex(a) from v1; 1499drop table t1; 1500drop view v1; 1501 1502create table t1 (a time); 1503insert into t1 values (1); 1504insert into t1 values ('01:02:03'); 1505create view v1(a) as select concat(a) from t1; 1506show columns from v1; 1507select hex(a) from v1; 1508drop table t1; 1509drop view v1; 1510 1511create table t1 (a datetime); 1512insert into t1 values ('2001-02-03 04:05:06'); 1513insert into t1 values (20010203040506); 1514create view v1(a) as select concat(a) from t1; 1515show columns from v1; 1516select hex(a) from v1; 1517drop table t1; 1518drop view v1; 1519 1520# 1521# User defined function returning numeric result 1522# 1523delimiter |; 1524create function f1 (par1 int) returns int 1525begin 1526return concat(par1); 1527end| 1528delimiter ;| 1529 1530set @a= f1(1); 1531select hex(@a); 1532select hex(concat(f1(1))); 1533create table t1 as select f1(1) as c1; 1534show create table t1; 1535drop table t1; 1536create table t1 as select concat(f1(1)) as c1; 1537show create table t1; 1538create view v1 as select concat(f1(1)) as c1; 1539show columns from v1; 1540drop table t1; 1541drop view v1; 1542drop function f1; 1543 1544delimiter |; 1545create function f1 (par1 decimal(18,2)) returns decimal(18,2) 1546begin 1547return concat(par1); 1548end| 1549delimiter ;| 1550 1551set @a= f1(123.45); 1552select hex(@a); 1553select hex(concat(f1(123.45))); 1554create table t1 as select f1(123.45) as c1; 1555show create table t1; 1556drop table t1; 1557create table t1 as select concat(f1(123.45)) as c1; 1558show create table t1; 1559create view v1 as select concat(f1(123.45)) as c1; 1560show columns from v1; 1561drop table t1; 1562drop view v1; 1563drop function f1; 1564 1565delimiter |; 1566create function f1 (par1 float) returns float 1567begin 1568return concat(par1); 1569end| 1570delimiter ;| 1571 1572set @a= f1(123.45); 1573select hex(@a); 1574select hex(concat(f1(123.45))); 1575create table t1 as select f1(123.45) as c1; 1576show create table t1; 1577drop table t1; 1578create table t1 as select concat(f1(123.45)) as c1; 1579show create table t1; 1580create view v1 as select concat(f1(123.45)) as c1; 1581show columns from v1; 1582drop table t1; 1583drop view v1; 1584drop function f1; 1585 1586delimiter |; 1587create function f1 (par1 date) returns date 1588begin 1589return concat(par1); 1590end| 1591delimiter ;| 1592 1593set @a= f1(cast('2001-01-02' as date)); 1594select hex(@a); 1595select hex(concat(f1(cast('2001-01-02' as date)))); 1596create table t1 as select f1(cast('2001-01-02' as date)) as c1; 1597show create table t1; 1598drop table t1; 1599create table t1 as select concat(f1(cast('2001-01-02' as date))) as c1; 1600show create table t1; 1601create view v1 as select concat(f1(cast('2001-01-02' as date))) as c1; 1602show columns from v1; 1603drop table t1; 1604drop view v1; 1605drop function f1; 1606 1607 1608--echo # 1609--echo # End of WL#2649 Number-to-string conversions 1610--echo # 1611 1612--echo # 1613--echo # Bug#54668 User variable assignments get wrong type 1614--echo # 1615SET @x=md5('a'); 1616SELECT charset(@x), collation(@x); 1617SET @x=old_password('a'); 1618SELECT charset(@x), collation(@x); 1619SET @x=password('a'); 1620SELECT charset(@x), collation(@x); 1621SET @x=sha('a'); 1622SELECT charset(@x), collation(@x); 1623SET @x=sha1('a'); 1624SELECT charset(@x), collation(@x); 1625SET @x=astext(point(1,2)); 1626SELECT charset(@x), collation(@x); 1627SET @x=aswkt(point(1,2)); 1628SELECT charset(@x), collation(@x); 1629 1630 1631--echo # 1632--echo # Bug#54916 GROUP_CONCAT + IFNULL truncates output 1633--echo # 1634SELECT @@collation_connection; 1635# ENGINE=MYISAM is very important to make sure "SYSTEM" join type 1636# is in use, which will create instances of Item_copy. 1637CREATE TABLE t1 (a MEDIUMINT NULL) ENGINE=MYISAM; 1638INSERT INTO t1 VALUES (1234567); 1639SELECT GROUP_CONCAT(IFNULL(a,'')) FROM t1; 1640SELECT GROUP_CONCAT(IF(a,a,'')) FROM t1; 1641SELECT GROUP_CONCAT(CASE WHEN a THEN a ELSE '' END) FROM t1; 1642--enable_metadata 1643SELECT COALESCE(a,'') FROM t1 GROUP BY 1; 1644--disable_metadata 1645--echo # All columns must be VARCHAR(9) with the same length: 1646--disable_warnings 1647CREATE TABLE t2 AS 1648SELECT 1649 CONCAT(a), 1650 IFNULL(a,''), 1651 IF(a,a,''), 1652 CASE WHEN a THEN a ELSE '' END, 1653 COALESCE(a,'') 1654FROM t1; 1655--enable_warnings 1656# The above query is expected to send a warning 1657# in case of ucs2 character set, until Bug#55744 is fixed. 1658SHOW CREATE TABLE t2; 1659DROP TABLE t2; 1660 1661CREATE TABLE t2 AS SELECT CONCAT_WS(1,2,3) FROM t1; 1662SHOW CREATE TABLE t2; 1663DROP TABLE t2; 1664 1665CREATE TABLE t2 AS SELECT INSERT(1133,3,0,22) FROM t1; 1666SHOW CREATE TABLE t2; 1667DROP TABLE t2; 1668 1669CREATE TABLE t2 AS SELECT LCASE(a) FROM t1; 1670SHOW CREATE TABLE t2; 1671DROP TABLE t2; 1672 1673CREATE TABLE t2 AS SELECT UCASE(a) FROM t1; 1674SHOW CREATE TABLE t2; 1675DROP TABLE t2; 1676 1677CREATE TABLE t2 AS SELECT REPEAT(1,2) FROM t1; 1678SHOW CREATE TABLE t2; 1679DROP TABLE t2; 1680 1681CREATE TABLE t2 AS SELECT LEFT(123,2) FROM t1; 1682SHOW CREATE TABLE t2; 1683DROP TABLE t2; 1684 1685CREATE TABLE t2 AS SELECT RIGHT(123,2) FROM t1; 1686SHOW CREATE TABLE t2; 1687DROP TABLE t2; 1688 1689CREATE TABLE t2 AS SELECT LTRIM(123) FROM t1; 1690SHOW CREATE TABLE t2; 1691DROP TABLE t2; 1692 1693CREATE TABLE t2 AS SELECT RTRIM(123) FROM t1; 1694SHOW CREATE TABLE t2; 1695DROP TABLE t2; 1696 1697CREATE TABLE t2 AS SELECT ELT(1,111,222,333) FROM t1; 1698SHOW CREATE TABLE t2; 1699DROP TABLE t2; 1700 1701CREATE TABLE t2 AS SELECT REPLACE(111,2,3) FROM t1; 1702SHOW CREATE TABLE t2; 1703DROP TABLE t2; 1704 1705CREATE TABLE t2 AS SELECT SUBSTRING_INDEX(111,111,1) FROM t1; 1706SHOW CREATE TABLE t2; 1707DROP TABLE t2; 1708 1709CREATE TABLE t2 AS SELECT MAKE_SET(111,222,3) FROM t1; 1710SHOW CREATE TABLE t2; 1711DROP TABLE t2; 1712 1713CREATE TABLE t2 AS SELECT SOUNDEX(1) FROM t1; 1714SHOW CREATE TABLE t2; 1715DROP TABLE t2; 1716 1717CREATE TABLE t2 AS SELECT EXPORT_SET(1,'Y','N','',8); 1718SHOW CREATE TABLE t2; 1719DROP TABLE t2; 1720 1721DROP TABLE t1; 1722 1723--echo # 1724--echo # End of Bug#54916 1725--echo # 1726 1727 1728--echo # 1729--echo # Bug#58190 BETWEEN no longer uses indexes for date or datetime fields 1730--echo # 1731SELECT @@collation_connection; 1732CREATE TABLE t1 ( 1733 id INT(11) DEFAULT NULL, 1734 date_column DATE DEFAULT NULL, 1735 KEY(date_column)); 1736INSERT INTO t1 VALUES (1,'2010-09-01'),(2,'2010-10-01'); 1737EXPLAIN SELECT * FROM t1 WHERE date_column BETWEEN '2010-09-01' AND '2010-10-01'; 1738ALTER TABLE t1 MODIFY date_column DATETIME DEFAULT NULL; 1739EXPLAIN SELECT * FROM t1 WHERE date_column BETWEEN '2010-09-01' AND '2010-10-01'; 1740DROP TABLE t1; 1741 1742 1743--echo # 1744--echo # Bug #31384 DATE_ADD() and DATE_SUB() return binary data 1745--echo # 1746SELECT @@collation_connection, @@character_set_results; 1747SELECT 1748 CHARSET(DATE_SUB('2007-08-03', INTERVAL 1 MINUTE)) AS field_str1, 1749 CHARSET(DATE_SUB('2007-08-03 17:33:00', INTERVAL 1 MINUTE)) AS field_str2, 1750 CHARSET(DATE_SUB(DATE('2007-08-03'), INTERVAL 1 DAY)) AS field_date, 1751 CHARSET(DATE_SUB(CAST('2007-08-03 17:33:00' AS DATETIME), INTERVAL 1 MINUTE)) AS field_datetime; 1752CREATE TABLE t1 AS 1753SELECT 1754 DATE_SUB('2007-08-03', INTERVAL 1 MINUTE) AS field_str1, 1755 DATE_SUB('2007-08-03 17:33:00', INTERVAL 1 MINUTE) AS field1_str2, 1756 DATE_SUB(DATE('2007-08-03'), INTERVAL 1 DAY) AS field_date, 1757 DATE_SUB(CAST('2007-08-03 17:33:00' AS DATETIME), INTERVAL 1 MINUTE) AS field_datetime; 1758SHOW CREATE TABLE t1; 1759DROP TABLE t1; 1760--enable_metadata 1761# PS protocol gives different "Max length" value for DATETIME. 1762--disable_ps_protocol 1763SELECT 1764 DATE_SUB('2007-08-03', INTERVAL 1 DAY) AS field_str1, 1765 DATE_SUB('2007-08-03 17:33:00', INTERVAL 1 MINUTE) AS field1_str2, 1766 DATE_SUB(DATE('2007-08-03'), INTERVAL 1 DAY) AS field_date, 1767 DATE_SUB(CAST('2007-08-03 17:33:00' AS DATETIME), INTERVAL 1 MINUTE) AS field_datetime; 1768--disable_metadata 1769--enable_ps_protocol 1770SELECT 1771 HEX(DATE_SUB('2007-08-03', INTERVAL 1 MINUTE)) AS field_str1, 1772 HEX(DATE_SUB('2007-08-03 17:33:00', INTERVAL 1 MINUTE)) AS field1_str2, 1773 HEX(DATE_SUB(DATE('2007-08-03'), INTERVAL 1 DAY)) AS field_date, 1774 HEX(DATE_SUB(CAST('2007-08-03 17:33:00' AS DATETIME), INTERVAL 1 MINUTE)) AS field_datetime; 1775 1776--echo # 1777--echo # MDEV-4841 Wrong character set of ADDTIME() and DATE_ADD() 1778--echo # 1779SELECT @@collation_connection, @@character_set_results; 1780SELECT 1781 CHARSET(ADDTIME(_latin1'10:01:01',_latin1'10:00:00')) AS addtime1, 1782 CHARSET(ADDTIME('10:01:01','10:00:00')) AS addtime2, 1783 CHARSET(DATE_ADD(_latin1'2001-01-01 10:01:01',interval 10 second)) AS date_add1, 1784 CHARSET(DATE_ADD('2001-01-01 10:01:01',interval 10 second)) AS date_add2; 1785CREATE TABLE t1 AS 1786SELECT 1787 ADDTIME(_latin1'10:01:01',_latin1'10:00:00') AS addtime1, 1788 ADDTIME('10:01:01','10:00:00') AS addtime2, 1789 DATE_ADD(_latin1'2001-01-01 10:01:01',interval 10 second) AS date_add1, 1790 DATE_ADD('2001-01-01 10:01:01',interval 10 second) AS date_add2; 1791SHOW CREATE TABLE t1; 1792SELECT * FROM t1; 1793DROP TABLE t1; 1794 1795--echo # 1796--echo # Bug#11926811 / Bug#60625 Illegal mix of collations 1797--echo # 1798SELECT @@collation_connection; 1799DELIMITER //; 1800CREATE PROCEDURE p1() 1801BEGIN 1802 DECLARE v_LastPaymentDate DATETIME DEFAULT NULL; 1803 SELECT v_LastPaymentDate < NOW(); 1804 EXPLAIN EXTENDED SELECT v_LastPaymentDate < NOW(); 1805 SHOW WARNINGS; 1806 EXPLAIN EXTENDED SELECT CONCAT(v_LastPaymentDate, NOW()); 1807END// 1808DELIMITER ;// 1809CALL p1; 1810DROP PROCEDURE p1; 1811 1812--echo # 1813--echo # Bug#52159 returning time type from function and empty left join causes debug assertion 1814--echo # 1815CREATE FUNCTION f1() RETURNS TIME RETURN 1; 1816CREATE TABLE t1 (b INT); 1817INSERT INTO t1 VALUES (0); 1818SELECT f1() FROM t1 LEFT JOIN (SELECT 1 AS a FROM t1 LIMIT 0) AS d ON 1 GROUP BY a; 1819DROP FUNCTION f1; 1820DROP TABLE t1; 1821 1822--echo # 1823--echo # MDEV-9662 Assertion `precision || !scale' failed in my_decimal_precision_to_length_no_truncation(uint, uint8, bool) 1824--echo # 1825SELECT @@collation_connection; 1826SELECT CASE 1 WHEN 2 THEN ( - '3' ) END; 1827 1828--echo # 1829--echo # MDEV-5702 Incorrect results are returned with NULLIF() 1830--echo # 1831CREATE TABLE t1 (d DATE); 1832INSERT INTO t1 VALUES ('1999-11-11'),('2014-02-04'); 1833SELECT DISTINCT d, CAST(d AS CHAR), NULLIF(d,"2000-01-01") AS bad, NULLIF(CAST(d AS CHAR),"2000-01-01") AS good FROM t1; 1834CREATE TABLE t2 AS SELECT DISTINCT d, NULLIF(d,'2000-01-01') AS bad FROM t1; 1835SHOW CREATE TABLE t2; 1836DROP TABLE t1, t2; 1837 1838 1839SET NAMES latin1; 1840SET sql_mode=''; 1841CREATE TABLE t1(a char(215) CHARACTER SET utf8 NOT NULL DEFAULT '', KEY(a)); 1842INSERT INTO t1 VALUES (); 1843--disable_warnings 1844SELECT maketime(`a`,`a`,`a`) FROM t1 GROUP BY 1; 1845--enable_warnings 1846DROP TABLE t1; 1847SET sql_mode=default; 1848