334
341
# Test types of data for create select with functions
337
create table t1(a int,b int,c int,d date,e char,f datetime,g time,h blob);
344
create table t1(a int,b int,c int,d date,e char,f datetime,h blob);
338
345
insert into t1(a)values(1);
339
insert into t1(a,b,c,d,e,f,g,h)
340
values(2,-2,2,'1825-12-14','a','2003-1-1 3:2:1','4:3:2','binary data');
346
insert into t1(a,b,c,d,e,f,h)
347
values(2,-2,2,'1825-12-14','a','2003-01-01 03:02:01','binary data');
341
348
select * from t1;
343
ifnull(b,cast(-7 as signed)) as b,
344
ifnull(c,cast(7 as)) as c,
345
352
ifnull(d,cast('2000-01-01' as date)) as d,
346
353
ifnull(e,cast('b' as char)) as e,
347
354
ifnull(f,cast('2000-01-01' as datetime)) as f,
348
ifnull(g,cast('5:4:3' as time)) as g,
349
ifnull(h,cast('yet another binary data' as binary)) as h,
350
addtime(cast('1:0:0' as time),cast('1:0:0' as time)) as dd
355
ifnull(h,cast('yet another binary data' as binary)) as h
356
ifnull(b,cast(-7 as signed)) as b,
357
ifnull(c,cast(7 as)) as c,
358
363
ifnull(d,cast('2000-01-01' as date)) as d,
359
364
ifnull(e,cast('b' as char)) as e,
360
365
ifnull(f,cast('2000-01-01' as datetime)) as f,
361
ifnull(g,cast('5:4:3' as time)) as g,
362
ifnull(h,cast('yet another binary data' as binary)) as h,
363
addtime(cast('1:0:0' as time),cast('1:0:0' as time)) as dd
366
ifnull(h,cast('yet another binary data' as binary)) as h
366
369
select * from t2;
367
370
drop table t1, t2;
369
create table t1 (a int, b int, c mediumint, d int, e bigint, f float(3,2), g double(4,3), h decimal(5,4), i year, j date, k timestamp, l datetime, m enum('a','b'), n set('a','b'), o char(10));
370
create table t2 select ifnull(a,a), ifnull(b,b), ifnull(c,c), ifnull(d,d), ifnull(e,e), ifnull(f,f), ifnull(g,g), ifnull(h,h), ifnull(i,i), ifnull(j,j), ifnull(k,k), ifnull(l,l), ifnull(m,m), ifnull(n,n), ifnull(o,o) from t1;
372
create table t1 (a int, b int, d int, e bigint, f float(3,2), g double(4,3), h decimal(5,4), j date, k timestamp, l datetime, m enum('a','b'), o char(10));
373
create table t2 select ifnull(a,a), ifnull(b,b), ifnull(d,d), ifnull(e,e), ifnull(f,f), ifnull(g,g), ifnull(h,h), ifnull(j,j), ifnull(k,k), ifnull(l,l), ifnull(m,m), ifnull(o,o) from t1;
371
374
show create table t2;
372
375
drop table t1,t2;
409
414
select database();
410
415
drop database mysqltest;
411
416
select database();
413
# Connect without a database as user mysqltest_1
414
create user mysqltest_1;
415
connect (user1,localhost,mysqltest_1,,*NO-ONE*);
417
select database(), user();
420
drop user mysqltest_1;
424
420
# Test for Bug 856 'Naming a key "Primary" causes trouble'
428
create table t1 (a int, index `primary` (a));
430
create table t1 (a int, index `PRIMARY` (a));
432
create table t1 (`primary` int, index(`primary`));
433
show create table t1;
434
create table t2 (`PRIMARY` int, index(`PRIMARY`));
435
show create table t2;
437
create table t3 (a int);
439
alter table t3 add index `primary` (a);
441
alter table t3 add index `PRIMARY` (a);
443
create table t4 (`primary` int);
444
alter table t4 add index(`primary`);
445
show create table t4;
446
create table t5 (`PRIMARY` int);
447
alter table t5 add index(`PRIMARY`);
448
show create table t5;
450
drop table t1, t2, t3, t4, t5;
423
## TODO: Is this really a bug? It works in Drizzle. Should it?
425
#create table t1 (a int, index `primary` (a));
427
#create table t1 (a int, index `PRIMARY` (a));
429
#create table t1 (`primary` int, index(`primary`));
430
#show create table t1;
431
#create table t2 (`PRIMARY` int, index(`PRIMARY`));
432
#show create table t2;
434
#create table t3 (a int);
436
#alter table t3 add index `primary` (a);
438
#alter table t3 add index `PRIMARY` (a);
440
#create table t4 (`primary` int);
441
#alter table t4 add index(`primary`);
442
#show create table t4;
443
#create table t5 (`PRIMARY` int);
444
#alter table t5 add index(`PRIMARY`);
445
#show create table t5;
447
#drop table t1, t2, t3, t4, t5;
453
450
# bug #3266 TEXT in CREATE TABLE SELECT
565
542
# calculation of number of NULLs.
567
544
CREATE TABLE t2 (
568
a int(11) default NULL
570
547
insert into t2 values(111);
573
550
create table t1 (
574
a varchar(12) charset utf8 collate utf8_bin not null,
551
a varchar(12) collate utf8_bin not null,
575
552
b int not null, primary key (a)
576
553
) select a, 1 as b from t2 ;
577
554
show create table t1;
581
558
create table t1 (
582
a varchar(12) charset utf8 collate utf8_bin not null,
559
a varchar(12) collate utf8_bin not null,
583
560
b int not null, primary key (a)
584
561
) select a, 1 as c from t2 ;
585
show create table t1;
589
563
create table t1 (
590
a varchar(12) charset utf8 collate utf8_bin not null,
564
a varchar(12) collate utf8_bin not null,
591
565
b int null, primary key (a)
592
566
) select a, 1 as c from t2 ;
593
567
show create table t1;
597
570
create table t1 (
598
a varchar(12) charset utf8 collate utf8_bin not null,
571
a varchar(12) collate utf8_bin not null,
599
572
b int not null, primary key (a)
600
573
) select 'a' as a , 1 as b from t2 ;
601
574
show create table t1;
605
577
create table t1 (
606
a varchar(12) charset utf8 collate utf8_bin,
578
a varchar(12) collate utf8_bin,
607
579
b int not null, primary key (a)
608
580
) select 'a' as a , 1 as b from t2 ;
609
581
show create table t1;
688
652
create table t1 select * from t1;
689
653
# Error which happens before select_create::prepare()
690
654
--error ER_CANT_AGGREGATE_2COLLATIONS
691
create table t1 select coalesce('a' collate latin1_swedish_ci,'b' collate latin1_bin);
655
create table t1 select coalesce('a' collate utf8_swedish_ci,'b' collate utf8_bin);
692
656
# Error during table creation
693
657
--error ER_KEY_COLUMN_DOES_NOT_EXITS
694
658
create table t1 (primary key(a)) select "b" as b;
695
659
# Error in select_create::prepare() which is not related to table creation
696
create table t1 (a int);
697
--error ER_WRONG_VALUE_COUNT_ON_ROW
698
create table if not exists t1 select 1 as a, 2 as b;
660
# TODO: This really should be failing...
661
# create table t1 (a int);
662
# --error ER_WRONG_VALUE_COUNT_ON_ROW
663
# create table if not exists t1 select 1 as a, 2 as b;
700
665
# Finally error which happens during insert
701
666
--error ER_DUP_ENTRY
702
667
create table t1 (primary key (a)) (select 1 as a) union all (select 1 as a);
703
668
# What happens if table already exists ?
704
669
create table t1 (i int);
705
--error ER_TABLE_EXISTS_ERROR
706
create table t1 select 1 as i;
670
# TODO: BUG lp:311045
671
#--error ER_TABLE_EXISTS_ERROR
672
#create table t1 select 1 as i;
707
673
create table if not exists t1 select 1 as i;
708
674
select * from t1;
709
676
# Error before select_create::prepare()
710
677
--error ER_CANT_AGGREGATE_2COLLATIONS
711
create table t1 select coalesce('a' collate latin1_swedish_ci,'b' collate latin1_bin);
678
create table t1 select coalesce('a' collate utf8_swedish_ci,'b' collate utf8_bin);
713
679
# Error which happens during insertion of rows
714
alter table t1 add primary key (i);
716
create table if not exists t1 (select 2 as i) union all (select 2 as i);
680
# TODO: Bug lp:311072
681
# create table t1 (i int);
682
# alter table t1 add primary key (i);
683
# --error ER_DUP_ENTRY
684
# create table if not exists t1 (select 2 as i) union all (select 2 as i);
721
689
# Base vs temporary tables dillema (a.k.a. bug#24508 "Inconsistent
1273
1238
select INDEX_NAME from information_schema.statistics where
1274
1239
table_schema='test';
1276
select TABLE_NAME from information_schema.views where
1277
table_schema='test';
1279
1241
show create table имя_таблицы_в_кодировке_утф8_длиной_больше_чем_48;
1280
show create view имя_вью_кодировке_утф8_длиной_больше_чем_42;
1282
# procedure, function, trigger
1284
create trigger имя_триггера_в_кодировке_утф8_длиной_больше_чем_49
1285
before insert on имя_таблицы_в_кодировке_утф8_длиной_больше_чем_48 for each row set @a:=1;
1286
select TRIGGER_NAME from information_schema.triggers where
1287
trigger_schema='test';
1288
drop trigger имя_триггера_в_кодировке_утф8_длиной_больше_чем_49;
1291
очень_очень_очень_очень_очень_очень_очень_очень_длинная_строка_66
1292
before insert on имя_таблицы_в_кодировке_утф8_длиной_больше_чем_48 for each row set @a:=1;
1294
drop trigger очень_очень_очень_очень_очень_очень_очень_очень_длинная_строка_66;
1296
create procedure имя_процедуры_в_кодировке_утф8_длиной_больше_чем_50()
1299
select ROUTINE_NAME from information_schema.routines where
1300
routine_schema='test';
1301
drop procedure имя_процедуры_в_кодировке_утф8_длиной_больше_чем_50;
1303
create procedure очень_очень_очень_очень_очень_очень_очень_очень_длинная_строка_66()
1307
create function имя_функции_в_кодировке_утф8_длиной_больше_чем_49()
1310
select ROUTINE_NAME from information_schema.routines where
1311
routine_schema='test';
1312
drop function имя_функции_в_кодировке_утф8_длиной_больше_чем_49;
1314
create function очень_очень_очень_очень_очень_очень_очень_очень_длинная_строка_66()
1318
drop view имя_вью_кодировке_утф8_длиной_больше_чем_42;
1319
1243
drop table имя_таблицы_в_кодировке_утф8_длиной_больше_чем_48;
1323
# Bug#21136 CREATE TABLE SELECT within CREATE TABLE SELECT causes server crash
1327
drop table if exists t1,t2,t3;
1328
drop function if exists f1;
1332
create function f1() returns int
1335
create temporary table t3 select 1 i;
1336
set res:= (select count(*) from t1);
1337
drop temporary table t3;
1341
create table t1 as select 1;
1342
create table t2 as select f1() from t1;
1347
1247
# Bug#25629 CREATE TABLE LIKE does not work with INFORMATION_SCHEMA