~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/r/case.result

  • Committer: Monty Taylor
  • Date: 2008-08-01 23:59:59 UTC
  • mto: (236.1.42 codestyle)
  • mto: This revision was merged to the branch mainline in revision 261.
  • Revision ID: monty@inaugust.com-20080801235959-n8ypy9r5aohown77
Gettext error compiles and passes test!

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
 
case 1/0 when "a" then "true" else "false" END
42
 
false
43
 
Warnings:
44
 
Error   1365    Division by 0
45
 
select case 1/0 when "a" then "true" END;
46
 
case 1/0 when "a" then "true" END
47
 
NULL
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)
52
 
NULL
53
 
Warnings:
54
 
Error   1365    Division by 0
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
58
 
Warnings:
59
 
Error   1365    Division by 0
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:
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)
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 
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,
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
108
 
t1      CREATE TABLE `t1` (
109
 
  `c1` VARCHAR(1) COLLATE utf8_bin DEFAULT NULL,
110
 
  `c2` VARCHAR(1) COLLATE utf8_bin DEFAULT NULL,
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,
117
 
  `c9` DECIMAL(2,1) DEFAULT NULL,
118
 
  `c10` DOUBLE NOT NULL,
119
 
  `c11` DOUBLE NOT NULL,
120
 
  `c12` VARBINARY(5) NOT NULL
121
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
122
 
DROP TABLE t1;
123
 
SELECT CASE 
124
 
WHEN 1 
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'
134
 
SELECT 
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
139
 
;
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
141
 
1       2       1       2
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'
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'),
147
 
COALESCE('a' COLLATE utf8_bin,'b');
148
 
explain extended SELECT 
149
 
COALESCE(1), COALESCE(1.0),COALESCE('a'),
150
 
COALESCE(1,1.0), COALESCE(1,'1'),COALESCE(1.1,'1'),
151
 
COALESCE('a' COLLATE utf8_bin,'b');
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:
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')`
156
 
SHOW CREATE TABLE t1;
157
 
Table   Create Table
158
 
t1      CREATE TABLE `t1` (
159
 
  `COALESCE(1)` INT NOT NULL,
160
 
  `COALESCE(1.0)` DECIMAL(2,1) NOT NULL,
161
 
  `COALESCE('a')` VARCHAR(1) COLLATE utf8_general_ci 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,
165
 
  `COALESCE('a' COLLATE utf8_bin,'b')` VARCHAR(1) COLLATE utf8_bin DEFAULT NULL
166
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
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
209
 
create table t1 (a int, b bigint);
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
217
 
3       -7326307919518956530
218
 
2       -250649785809709619
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
223
 
3       -7326307919518956530
224
 
drop table t1, t2;
225
 
End of 5.0 tests