~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/r/case.result

Removed/replaced DBUG symbols and standardized TRUE/FALSE

Show diffs side-by-side

added added

removed removed

Lines of Context:
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:
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`
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
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)
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
 
ERROR 22012: Division by 0
42
 
select case 1/0 when "a" then "true" END;
43
 
ERROR 22012: Division by 0
44
 
select (case 1/0 when "a" then "true" END);
45
 
ERROR 22012: Division by 0
46
 
select (case 1/0 when "a" then "true" END) + 0.0;
47
 
ERROR 22012: Division by 0
48
 
select case when 1>0 then "TRUE" else "FALSE" END;
49
 
case when 1>0 then "TRUE" else "FALSE" END
50
 
TRUE
51
 
select case when 1<0 then "TRUE" else "FALSE" END;
52
 
case when 1<0 then "TRUE" else "FALSE" END
53
 
FALSE
54
 
create table t1 (a int);
55
 
insert into t1 values(1),(2),(3),(4);
56
 
select case a when 1 then 2 when 2 then 3 else 0 end as fcase, count(*) from t1 group by fcase;
57
 
fcase   count(*)
58
 
0       2
59
 
2       1
60
 
3       1
61
 
explain extended select case a when 1 then 2 when 2 then 3 else 0 end as fcase, count(*) from t1 group by fcase;
62
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
63
 
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    4       100.00  Using temporary; Using filesort
64
 
Warnings:
65
 
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)
66
 
select case a when 1 then "one" when 2 then "two" else "nothing" end as fcase, count(*) from t1 group by fcase;
67
 
fcase   count(*)
68
 
nothing 2
69
 
one     1
70
 
two     1
71
 
drop table t1;
72
 
create table t1 (row int not null, col int not null, val varchar(255) not null);
73
 
insert into t1 values (1,1,'orange'),(1,2,'large'),(2,1,'yellow'),(2,2,'medium'),(3,1,'green'),(3,2,'small');
74
 
select max(case col when 1 then val else null end) as color from t1 group by row;
75
 
color
76
 
orange
77
 
yellow
78
 
green
79
 
drop table t1;
80
 
CREATE TABLE t1 SELECT 
81
 
CASE WHEN 1 THEN 'a' COLLATE utf8_bin ELSE 'a' END AS c1,
82
 
CASE WHEN 1 THEN 'a' ELSE 'a' COLLATE utf8_bin END AS c2,
83
 
CASE WHEN 1 THEN 'a' ELSE  1  END AS c3,
84
 
CASE WHEN 1 THEN  1  ELSE 'a' END AS c4,
85
 
CASE WHEN 1 THEN 'a' ELSE 1.0 END AS c5,
86
 
CASE WHEN 1 THEN 1.0 ELSE 'a' END AS c6,
87
 
CASE WHEN 1 THEN  1  ELSE 1.0 END AS c7,
88
 
CASE WHEN 1 THEN 1.0 ELSE  1  END AS c8,
89
 
CASE WHEN 1 THEN 1.0 END AS c9,
90
 
CASE WHEN 1 THEN 0.1e1 else 0.1 END AS c10,
91
 
CASE WHEN 1 THEN 0.1e1 else 1 END AS c11,
92
 
CASE WHEN 1 THEN 0.1e1 else '1' END AS c12
93
 
;
94
 
SHOW CREATE TABLE t1;
95
 
Table   Create Table
96
 
t1      CREATE TABLE `t1` (
97
 
  `c1` VARCHAR(1) COLLATE utf8_bin DEFAULT NULL,
98
 
  `c2` VARCHAR(1) COLLATE utf8_bin DEFAULT NULL,
99
 
  `c3` VARBINARY(4) NOT NULL,
100
 
  `c4` VARBINARY(4) NOT NULL,
101
 
  `c5` VARBINARY(4) NOT NULL,
102
 
  `c6` VARBINARY(4) NOT NULL,
103
 
  `c7` DECIMAL(2,1) NOT NULL,
104
 
  `c8` DECIMAL(2,1) NOT NULL,
105
 
  `c9` DECIMAL(2,1) DEFAULT NULL,
106
 
  `c10` DOUBLE NOT NULL,
107
 
  `c11` DOUBLE NOT NULL,
108
 
  `c12` VARBINARY(5) NOT NULL
109
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
110
 
DROP TABLE t1;
111
 
SELECT CASE 
112
 
WHEN 1 
113
 
THEN 'a' COLLATE utf8_bin 
114
 
ELSE 'a' COLLATE utf8_swedish_ci
115
 
END;
116
 
ERROR HY000: Illegal mix of collations (utf8_bin,EXPLICIT) and (utf8_swedish_ci,EXPLICIT) for operation 'case'
117
 
SELECT CASE 'a' COLLATE utf8_bin
118
 
WHEN 'a' COLLATE utf8_danish_ci  THEN 1
119
 
WHEN 'a' COLLATE utf8_swedish_ci THEN 2
120
 
END;
121
 
ERROR HY000: Illegal mix of collations (utf8_bin,EXPLICIT), (utf8_danish_ci,EXPLICIT), (utf8_swedish_ci,EXPLICIT) for operation 'case'
122
 
SELECT 
123
 
CASE 'a' COLLATE utf8_general_ci  WHEN 'A' THEN '1' ELSE 2 END,
124
 
CASE 'a' COLLATE utf8_bin         WHEN 'A' THEN '1' ELSE 2 END,
125
 
CASE 'a' WHEN 'A' COLLATE utf8_swedish_ci THEN '1' ELSE 2 END,
126
 
CASE 'a' WHEN 'A' COLLATE utf8_bin        THEN '1' ELSE 2 END
127
 
;
128
 
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
129
 
1       2       1       2
130
 
CREATE TABLE t1 SELECT COALESCE('a' COLLATE utf8_swedish_ci,'b' COLLATE utf8_bin);
131
 
ERROR HY000: Illegal mix of collations (utf8_swedish_ci,EXPLICIT) and (utf8_bin,EXPLICIT) for operation 'coalesce'
132
 
CREATE TABLE t1 SELECT 
133
 
COALESCE(1), COALESCE(1.0),COALESCE('a'),
134
 
COALESCE(1,1.0), COALESCE(1,'1'),COALESCE(1.1,'1'),
135
 
COALESCE('a' COLLATE utf8_bin,'b');
136
 
explain extended SELECT 
137
 
COALESCE(1), COALESCE(1.0),COALESCE('a'),
138
 
COALESCE(1,1.0), COALESCE(1,'1'),COALESCE(1.1,'1'),
139
 
COALESCE('a' COLLATE utf8_bin,'b');
140
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
141
 
1       SIMPLE  NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    No tables used
142
 
Warnings:
143
 
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')`
144
 
SHOW CREATE TABLE t1;
145
 
Table   Create Table
146
 
t1      CREATE TABLE `t1` (
147
 
  `COALESCE(1)` INT NOT NULL,
148
 
  `COALESCE(1.0)` DECIMAL(2,1) NOT NULL,
149
 
  `COALESCE('a')` VARCHAR(1) COLLATE utf8_general_ci NOT NULL,
150
 
  `COALESCE(1,1.0)` DECIMAL(2,1) NOT NULL,
151
 
  `COALESCE(1,'1')` VARBINARY(4) NOT NULL,
152
 
  `COALESCE(1.1,'1')` VARBINARY(4) NOT NULL,
153
 
  `COALESCE('a' COLLATE utf8_bin,'b')` VARCHAR(1) COLLATE utf8_bin DEFAULT NULL
154
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
155
 
DROP TABLE t1;
156
 
SELECT 'case+union+test'
157
 
UNION 
158
 
SELECT CASE LOWER('1') WHEN LOWER('2') THEN 'BUG' ELSE 'nobug' END;
159
 
case+union+test
160
 
case+union+test
161
 
nobug
162
 
SELECT CASE LOWER('1') WHEN LOWER('2') THEN 'BUG' ELSE 'nobug' END;
163
 
CASE LOWER('1') WHEN LOWER('2') THEN 'BUG' ELSE 'nobug' END
164
 
nobug
165
 
SELECT 'case+union+test'
166
 
UNION 
167
 
SELECT CASE '1' WHEN '2' THEN 'BUG' ELSE 'nobug' END;
168
 
case+union+test
169
 
case+union+test
170
 
nobug
171
 
create table t1(a float, b int default 3);
172
 
insert into t1 (a) values (2), (11), (8);
173
 
select min(a), min(case when 1=1 then a else NULL end),
174
 
min(case when 1!=1 then NULL else a end) 
175
 
from t1 where b=3 group by b;
176
 
min(a)  min(case when 1=1 then a else NULL end) min(case when 1!=1 then NULL else a end)
177
 
2       2       2
178
 
drop table t1;
179
 
CREATE TABLE t1 (EMPNUM INT);
180
 
INSERT INTO t1 VALUES (0), (2);
181
 
CREATE TABLE t2 (EMPNUM DECIMAL (4, 2));
182
 
INSERT INTO t2 VALUES (0.0), (9.0);
183
 
SELECT COALESCE(t2.EMPNUM,t1.EMPNUM) AS CEMPNUM,
184
 
t1.EMPNUM AS EMPMUM1, t2.EMPNUM AS EMPNUM2
185
 
FROM t1 LEFT JOIN t2 ON t1.EMPNUM=t2.EMPNUM;
186
 
CEMPNUM EMPMUM1 EMPNUM2
187
 
0.00    0       0.00
188
 
2.00    2       NULL
189
 
SELECT IFNULL(t2.EMPNUM,t1.EMPNUM) AS CEMPNUM,
190
 
t1.EMPNUM AS EMPMUM1, t2.EMPNUM AS EMPNUM2
191
 
FROM t1 LEFT JOIN t2 ON t1.EMPNUM=t2.EMPNUM;
192
 
CEMPNUM EMPMUM1 EMPNUM2
193
 
0.00    0       0.00
194
 
2.00    2       NULL
195
 
DROP TABLE t1,t2;
196
 
End of 4.1 tests
197
 
create table t1 (a int, b bigint unsigned);
198
 
create table t2 (c int);
199
 
insert into t1 (a, b) values (1,4572794622775114594), (2,18196094287899841997),
200
 
(3,11120436154190595086);
201
 
insert into t2 (c) values (1), (2), (3);
202
 
select t1.a, (case t1.a when 0 then 0 else t1.b end) d from t1 
203
 
join t2 on t1.a=t2.c order by d;
204
 
a       d
205
 
3       -7326307919518956530
206
 
2       -250649785809709619
207
 
1       4572794622775114594
208
 
select t1.a, (case t1.a when 0 then 0 else t1.b end) d from t1 
209
 
join t2 on t1.a=t2.c where b=11120436154190595086 order by d;
210
 
a       d
211
 
3       -7326307919518956530
212
 
drop table t1, t2;
213
 
End of 5.0 tests