~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
drop table if exists t1, t2;
2
select CASE "b" when "a" then 1 when "b" then 2 END;
3
CASE "b" when "a" then 1 when "b" then 2 END
4
2
5
select CASE "c" when "a" then 1 when "b" then 2 END;
6
CASE "c" when "a" then 1 when "b" then 2 END
7
NULL
8
select CASE "c" when "a" then 1 when "b" then 2 ELSE 3 END;
9
CASE "c" when "a" then 1 when "b" then 2 ELSE 3 END
10
3
11
select CASE BINARY "b" when "a" then 1 when "B" then 2 WHEN "b" then "ok" END;
12
CASE BINARY "b" when "a" then 1 when "B" then 2 WHEN "b" then "ok" END
13
ok
14
select CASE "b" when "a" then 1 when binary "B" then 2 WHEN "b" then "ok" END;
15
CASE "b" when "a" then 1 when binary "B" then 2 WHEN "b" then "ok" END
16
ok
17
select CASE concat("a","b") when concat("ab","") then "a" when "b" then "b" end;
18
CASE concat("a","b") when concat("ab","") then "a" when "b" then "b" end
19
a
20
select CASE when 1=0 then "true" else "false" END;
21
CASE when 1=0 then "true" else "false" END
22
false
23
select CASE 1 when 1 then "one" WHEN 2 then "two" ELSE "more" END;
24
CASE 1 when 1 then "one" WHEN 2 then "two" ELSE "more" END
25
one
26
explain extended select CASE 1 when 1 then "one" WHEN 2 then "two" ELSE "more" END;
27
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
28
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
29
Warnings:
685.2.4 by Monty Taylor
Fixed case test.
30
Note	1003	select (case 1 when 1 then 'one' when 2 then 'two' else 'more' end) AS `CASE 1 when 1 then "one" WHEN 2 then "two" ELSE "more" END`
1 by brian
clean slate
31
select CASE 2.0 when 1 then "one" WHEN 2.0 then "two" ELSE "more" END;
32
CASE 2.0 when 1 then "one" WHEN 2.0 then "two" ELSE "more" END
33
two
685.2.4 by Monty Taylor
Fixed case test.
34
select (CASE "two" when "one" then "1" WHEN "two" then "2" END);
35
(CASE "two" when "one" then "1" WHEN "two" then "2" END)
1 by brian
clean slate
36
2
37
select (CASE "two" when "one" then 1.00 WHEN "two" then 2.00 END) +0.0;
38
(CASE "two" when "one" then 1.00 WHEN "two" then 2.00 END) +0.0
39
2.00
40
select case 1/0 when "a" then "true" else "false" END;
41
case 1/0 when "a" then "true" else "false" END
42
false
685.2.4 by Monty Taylor
Fixed case test.
43
Warnings:
44
Error	1365	Division by 0
1 by brian
clean slate
45
select case 1/0 when "a" then "true" END;
46
case 1/0 when "a" then "true" END
47
NULL
685.2.4 by Monty Taylor
Fixed case test.
48
Warnings:
49
Error	1365	Division by 0
50
select (case 1/0 when "a" then "true" END);
51
(case 1/0 when "a" then "true" END)
1 by brian
clean slate
52
NULL
685.2.4 by Monty Taylor
Fixed case test.
53
Warnings:
54
Error	1365	Division by 0
1 by brian
clean slate
55
select (case 1/0 when "a" then "true" END) + 0.0;
56
(case 1/0 when "a" then "true" END) + 0.0
57
NULL
685.2.4 by Monty Taylor
Fixed case test.
58
Warnings:
59
Error	1365	Division by 0
1 by brian
clean slate
60
select case when 1>0 then "TRUE" else "FALSE" END;
61
case when 1>0 then "TRUE" else "FALSE" END
62
TRUE
63
select case when 1<0 then "TRUE" else "FALSE" END;
64
case when 1<0 then "TRUE" else "FALSE" END
65
FALSE
66
create table t1 (a int);
67
insert into t1 values(1),(2),(3),(4);
68
select case a when 1 then 2 when 2 then 3 else 0 end as fcase, count(*) from t1 group by fcase;
69
fcase	count(*)
70
0	2
71
2	1
72
3	1
73
explain extended select case a when 1 then 2 when 2 then 3 else 0 end as fcase, count(*) from t1 group by fcase;
74
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
75
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	4	100.00	Using temporary; Using filesort
76
Warnings:
685.2.4 by Monty Taylor
Fixed case test.
77
Note	1003	select (case `test`.`t1`.`a` when 1 then 2 when 2 then 3 else 0 end) AS `fcase`,count(0) AS `count(*)` from `test`.`t1` group by (case `test`.`t1`.`a` when 1 then 2 when 2 then 3 else 0 end)
1 by brian
clean slate
78
select case a when 1 then "one" when 2 then "two" else "nothing" end as fcase, count(*) from t1 group by fcase;
79
fcase	count(*)
80
nothing	2
81
one	1
82
two	1
83
drop table t1;
84
create table t1 (row int not null, col int not null, val varchar(255) not null);
85
insert into t1 values (1,1,'orange'),(1,2,'large'),(2,1,'yellow'),(2,2,'medium'),(3,1,'green'),(3,2,'small');
86
select max(case col when 1 then val else null end) as color from t1 group by row;
87
color
88
orange
89
yellow
90
green
91
drop table t1;
92
CREATE TABLE t1 SELECT 
685.2.4 by Monty Taylor
Fixed case test.
93
CASE WHEN 1 THEN 'a' COLLATE utf8_bin ELSE 'a' END AS c1,
94
CASE WHEN 1 THEN 'a' ELSE 'a' COLLATE utf8_bin END AS c2,
1 by brian
clean slate
95
CASE WHEN 1 THEN 'a' ELSE  1  END AS c3,
96
CASE WHEN 1 THEN  1  ELSE 'a' END AS c4,
97
CASE WHEN 1 THEN 'a' ELSE 1.0 END AS c5,
98
CASE WHEN 1 THEN 1.0 ELSE 'a' END AS c6,
99
CASE WHEN 1 THEN  1  ELSE 1.0 END AS c7,
100
CASE WHEN 1 THEN 1.0 ELSE  1  END AS c8,
101
CASE WHEN 1 THEN 1.0 END AS c9,
102
CASE WHEN 1 THEN 0.1e1 else 0.1 END AS c10,
103
CASE WHEN 1 THEN 0.1e1 else 1 END AS c11,
104
CASE WHEN 1 THEN 0.1e1 else '1' END AS c12
105
;
106
SHOW CREATE TABLE t1;
107
Table	Create Table
685.2.4 by Monty Taylor
Fixed case test.
108
t1	CREATE TABLE `t1` (
873.2.35 by Monty Taylor
Update tests based on how Toru's latest patch changes create table statements.
109
  `c1` varchar(1) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
110
  `c2` varchar(1) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
896.3.6 by Stewart Smith
Read Fields out of proto instead of FRM.
111
  `c3` varbinary(4) NOT NULL,
112
  `c4` varbinary(4) NOT NULL,
113
  `c5` varbinary(4) NOT NULL,
114
  `c6` varbinary(4) NOT NULL,
115
  `c7` decimal(2,1) NOT NULL,
116
  `c8` decimal(2,1) NOT NULL,
873.2.35 by Monty Taylor
Update tests based on how Toru's latest patch changes create table statements.
117
  `c9` decimal(2,1) DEFAULT NULL,
896.3.6 by Stewart Smith
Read Fields out of proto instead of FRM.
118
  `c10` double NOT NULL,
119
  `c11` double NOT NULL,
120
  `c12` varbinary(5) NOT NULL
942.3.1 by Vladimir Kolesnikov
test generalizations
121
) ENGINE=DEFAULT
1 by brian
clean slate
122
DROP TABLE t1;
123
SELECT CASE 
124
WHEN 1 
685.2.4 by Monty Taylor
Fixed case test.
125
THEN 'a' COLLATE utf8_bin 
126
ELSE 'a' COLLATE utf8_swedish_ci
127
END;
128
ERROR HY000: Illegal mix of collations (utf8_bin,EXPLICIT) and (utf8_swedish_ci,EXPLICIT) for operation 'case'
129
SELECT CASE 'a' COLLATE utf8_bin
130
WHEN 'a' COLLATE utf8_danish_ci  THEN 1
131
WHEN 'a' COLLATE utf8_swedish_ci THEN 2
132
END;
133
ERROR HY000: Illegal mix of collations (utf8_bin,EXPLICIT), (utf8_danish_ci,EXPLICIT), (utf8_swedish_ci,EXPLICIT) for operation 'case'
1 by brian
clean slate
134
SELECT 
685.2.4 by Monty Taylor
Fixed case test.
135
CASE 'a' COLLATE utf8_general_ci  WHEN 'A' THEN '1' ELSE 2 END,
136
CASE 'a' COLLATE utf8_bin         WHEN 'A' THEN '1' ELSE 2 END,
137
CASE 'a' WHEN 'A' COLLATE utf8_swedish_ci THEN '1' ELSE 2 END,
138
CASE 'a' WHEN 'A' COLLATE utf8_bin        THEN '1' ELSE 2 END
1 by brian
clean slate
139
;
685.2.4 by Monty Taylor
Fixed case test.
140
CASE 'a' COLLATE utf8_general_ci  WHEN 'A' THEN '1' ELSE 2 END	CASE 'a' COLLATE utf8_bin         WHEN 'A' THEN '1' ELSE 2 END	CASE 'a' WHEN 'A' COLLATE utf8_swedish_ci THEN '1' ELSE 2 END	CASE 'a' WHEN 'A' COLLATE utf8_bin        THEN '1' ELSE 2 END
1 by brian
clean slate
141
1	2	1	2
685.2.4 by Monty Taylor
Fixed case test.
142
CREATE TABLE t1 SELECT COALESCE('a' COLLATE utf8_swedish_ci,'b' COLLATE utf8_bin);
143
ERROR HY000: Illegal mix of collations (utf8_swedish_ci,EXPLICIT) and (utf8_bin,EXPLICIT) for operation 'coalesce'
1 by brian
clean slate
144
CREATE TABLE t1 SELECT 
145
COALESCE(1), COALESCE(1.0),COALESCE('a'),
146
COALESCE(1,1.0), COALESCE(1,'1'),COALESCE(1.1,'1'),
685.2.4 by Monty Taylor
Fixed case test.
147
COALESCE('a' COLLATE utf8_bin,'b');
1 by brian
clean slate
148
explain extended SELECT 
149
COALESCE(1), COALESCE(1.0),COALESCE('a'),
150
COALESCE(1,1.0), COALESCE(1,'1'),COALESCE(1.1,'1'),
685.2.4 by Monty Taylor
Fixed case test.
151
COALESCE('a' COLLATE utf8_bin,'b');
1 by brian
clean slate
152
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
153
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
154
Warnings:
685.2.4 by Monty Taylor
Fixed case test.
155
Note	1003	select coalesce(1) AS `COALESCE(1)`,coalesce(1.0) AS `COALESCE(1.0)`,coalesce('a') AS `COALESCE('a')`,coalesce(1,1.0) AS `COALESCE(1,1.0)`,coalesce(1,'1') AS `COALESCE(1,'1')`,coalesce(1.1,'1') AS `COALESCE(1.1,'1')`,coalesce(('a' collate utf8_bin),'b') AS `COALESCE('a' COLLATE utf8_bin,'b')`
1 by brian
clean slate
156
SHOW CREATE TABLE t1;
157
Table	Create Table
685.2.4 by Monty Taylor
Fixed case test.
158
t1	CREATE TABLE `t1` (
896.3.6 by Stewart Smith
Read Fields out of proto instead of FRM.
159
  `COALESCE(1)` int NOT NULL,
160
  `COALESCE(1.0)` decimal(2,1) NOT NULL,
161
  `COALESCE('a')` varchar(1) NOT NULL,
162
  `COALESCE(1,1.0)` decimal(2,1) NOT NULL,
163
  `COALESCE(1,'1')` varbinary(4) NOT NULL,
164
  `COALESCE(1.1,'1')` varbinary(4) NOT NULL,
873.2.35 by Monty Taylor
Update tests based on how Toru's latest patch changes create table statements.
165
  `COALESCE('a' COLLATE utf8_bin,'b')` varchar(1) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL
942.3.1 by Vladimir Kolesnikov
test generalizations
166
) ENGINE=DEFAULT
1 by brian
clean slate
167
DROP TABLE t1;
168
SELECT 'case+union+test'
169
UNION 
170
SELECT CASE LOWER('1') WHEN LOWER('2') THEN 'BUG' ELSE 'nobug' END;
171
case+union+test
172
case+union+test
173
nobug
174
SELECT CASE LOWER('1') WHEN LOWER('2') THEN 'BUG' ELSE 'nobug' END;
175
CASE LOWER('1') WHEN LOWER('2') THEN 'BUG' ELSE 'nobug' END
176
nobug
177
SELECT 'case+union+test'
178
UNION 
179
SELECT CASE '1' WHEN '2' THEN 'BUG' ELSE 'nobug' END;
180
case+union+test
181
case+union+test
182
nobug
183
create table t1(a float, b int default 3);
184
insert into t1 (a) values (2), (11), (8);
185
select min(a), min(case when 1=1 then a else NULL end),
186
min(case when 1!=1 then NULL else a end) 
187
from t1 where b=3 group by b;
188
min(a)	min(case when 1=1 then a else NULL end)	min(case when 1!=1 then NULL else a end)
189
2	2	2
190
drop table t1;
191
CREATE TABLE t1 (EMPNUM INT);
192
INSERT INTO t1 VALUES (0), (2);
193
CREATE TABLE t2 (EMPNUM DECIMAL (4, 2));
194
INSERT INTO t2 VALUES (0.0), (9.0);
195
SELECT COALESCE(t2.EMPNUM,t1.EMPNUM) AS CEMPNUM,
196
t1.EMPNUM AS EMPMUM1, t2.EMPNUM AS EMPNUM2
197
FROM t1 LEFT JOIN t2 ON t1.EMPNUM=t2.EMPNUM;
198
CEMPNUM	EMPMUM1	EMPNUM2
199
0.00	0	0.00
200
2.00	2	NULL
201
SELECT IFNULL(t2.EMPNUM,t1.EMPNUM) AS CEMPNUM,
202
t1.EMPNUM AS EMPMUM1, t2.EMPNUM AS EMPNUM2
203
FROM t1 LEFT JOIN t2 ON t1.EMPNUM=t2.EMPNUM;
204
CEMPNUM	EMPMUM1	EMPNUM2
205
0.00	0	0.00
206
2.00	2	NULL
207
DROP TABLE t1,t2;
208
End of 4.1 tests
685.2.4 by Monty Taylor
Fixed case test.
209
create table t1 (a int, b bigint);
1 by brian
clean slate
210
create table t2 (c int);
211
insert into t1 (a, b) values (1,4572794622775114594), (2,18196094287899841997),
212
(3,11120436154190595086);
213
insert into t2 (c) values (1), (2), (3);
214
select t1.a, (case t1.a when 0 then 0 else t1.b end) d from t1 
215
join t2 on t1.a=t2.c order by d;
216
a	d
685.2.4 by Monty Taylor
Fixed case test.
217
3	-7326307919518956530
218
2	-250649785809709619
1 by brian
clean slate
219
1	4572794622775114594
220
select t1.a, (case t1.a when 0 then 0 else t1.b end) d from t1 
221
join t2 on t1.a=t2.c where b=11120436154190595086 order by d;
222
a	d
685.2.4 by Monty Taylor
Fixed case test.
223
3	-7326307919518956530
1 by brian
clean slate
224
drop table t1, t2;
225
End of 5.0 tests