2
2
# Test of unions
3
3
#
4
4
5
- --disable_warnings
6
- drop table if exists t1,t2,t3,t4,t5,t6;
7
- --enable_warnings
8
-
9
5
CREATE TABLE t1 (a int not null, b char (10) not null);
10
6
insert into t1 values(1,'a'),(2,'b'),(3,'c'),(3,'c');
11
7
CREATE TABLE t2 (a int not null, b char (10) not null);
@@ -23,7 +19,7 @@ select 't1',b,count(*) from t1 group by b UNION select 't2',b,count(*) from t2 g
23
19
(select a,b from t1 limit 2) union all (select a,b from t2 order by a) limit 4;
24
20
(select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1);
25
21
(select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1) order by b desc;
26
- --error 1250
22
+ --error ER_TABLENAME_NOT_ALLOWED_HERE
27
23
(select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1) order by t1.b;
28
24
explain extended (select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1) order by b desc;
29
25
--disable_view_protocol
@@ -42,13 +38,13 @@ select found_rows();
42
38
43
39
explain select a,b from t1 union all select a,b from t2;
44
40
45
- --error 1054
41
+ --error ER_BAD_FIELD_ERROR
46
42
explain select xx from t1 union select 1;
47
- --error 1222
43
+ --error ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT
48
44
explain select a,b from t1 union select 1;
49
- --error 1222
45
+ --error ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT
50
46
explain select 1 union select a,b from t1 union select 1;
51
- --error 1222
47
+ --error ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT
52
48
explain select a,b from t1 union select 1 limit 0;
53
49
54
50
--error ER_PARSE_ERROR
@@ -60,19 +56,19 @@ select a,b from t1 order by a union select a,b from t2;
60
56
--error ER_PARSE_ERROR
61
57
insert into t3 select a from t1 order by a union select a from t2;
62
58
63
- --error 1222
59
+ --error ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT
64
60
create table t3 select a,b from t1 union select a from t2;
65
61
66
- --error 1222
62
+ --error ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT
67
63
select a,b from t1 union select a from t2;
68
64
69
- --error 1222
65
+ --error ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT
70
66
select * from t1 union select a from t2;
71
67
72
- --error 1222
68
+ --error ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT
73
69
select a from t1 union select * from t2;
74
70
75
- --error 1234
71
+ --error ER_CANT_USE_OPTION_HERE
76
72
select * from t1 union select SQL_BUFFER_RESULT * from t2;
77
73
78
74
# Test CREATE, INSERT and REPLACE
@@ -86,13 +82,13 @@ drop table t1,t2,t3;
86
82
#
87
83
# Test some unions without tables
88
84
#
89
- --error 1096
85
+ --error ER_NO_TABLES_USED
90
86
select * union select 1;
91
87
select 1 as a,(select a union select a);
92
- --error 1054
88
+ --error ER_BAD_FIELD_ERROR
93
89
(select 1) union (select 2) order by 0;
94
90
SELECT @a:=1 UNION SELECT @a:=@a+1;
95
- --error 1054
91
+ --error ER_BAD_FIELD_ERROR
96
92
(SELECT 1) UNION (SELECT 2) ORDER BY (SELECT a);
97
93
(SELECT 1,3) UNION (SELECT 2,1) ORDER BY (SELECT 2);
98
94
@@ -294,7 +290,7 @@ SELECT * FROM t1 UNION SELECT * FROM t2 ORDER BY a desc LIMIT 1;
294
290
(SELECT * FROM t1 ORDER by a) UNION ALL (SELECT * FROM t2 ORDER BY a) ORDER BY A desc LIMIT 4;
295
291
296
292
# Wrong usage
297
- --error 1234
293
+ --error ER_CANT_USE_OPTION_HERE
298
294
(SELECT * FROM t1) UNION all (SELECT SQL_CALC_FOUND_ROWS * FROM t2) LIMIT 1;
299
295
300
296
create temporary table t1 select a from t1 union select a from t2;
@@ -477,7 +473,7 @@ create table t1 select 1 union select -1;
477
473
select * from t1;
478
474
show create table t1;
479
475
drop table t1;
480
- -- error 1267
476
+ -- error ER_CANT_AGGREGATE_2COLLATIONS
481
477
create table t1 select _latin1"test" union select _latin2"testt" ;
482
478
create table t1 select _latin2"test" union select _latin2"testt" ;
483
479
show create table t1;
@@ -585,7 +581,7 @@ set sql_select_limit=default;
585
581
#
586
582
CREATE TABLE t1 (i int(11) default NULL,c char(1) default NULL,KEY i (i));
587
583
CREATE TABLE t2 (i int(11) default NULL,c char(1) default NULL,KEY i (i));
588
- --error 1054
584
+ --error ER_BAD_FIELD_ERROR
589
585
explain (select * from t1) union (select * from t2) order by not_existing_column;
590
586
drop table t1, t2;
591
587
@@ -687,7 +683,7 @@ drop table t1;
687
683
create table t2 (
688
684
a char character set latin1 collate latin1_swedish_ci,
689
685
b char character set latin1 collate latin1_german1_ci);
690
- --error 1271
686
+ --error ER_CANT_AGGREGATE_NCOLLATIONS
691
687
create table t1 as
692
688
(select a from t2) union
693
689
(select b from t2);
@@ -984,19 +980,19 @@ CREATE TABLE t1 (a int);
984
980
INSERT INTO t1 VALUES (3),(1),(2),(4),(1);
985
981
986
982
SELECT a FROM (SELECT a FROM t1 UNION SELECT a FROM t1 ORDER BY a) AS test;
987
- --error 1054
983
+ --error ER_BAD_FIELD_ERROR
988
984
SELECT a FROM (SELECT a FROM t1 UNION SELECT a FROM t1 ORDER BY c) AS test;
989
985
990
986
DROP TABLE t1;
991
987
992
988
#
993
989
# Bug#23345: Wrongly allowed INTO in a non-last select of a UNION.
994
990
#
995
- --error 1221
991
+ --error ER_WRONG_USAGE
996
992
(select 1 into @var) union (select 1);
997
993
(select 1) union (select 1 into @var);
998
994
select @var;
999
- --error 1172
995
+ --error ER_TOO_MANY_ROWS
1000
996
(select 2) union (select 1 into @var);
1001
997
1002
998
#
0 commit comments