1
drop table if exists t1,t2;
3
ERROR 42S22: Unknown column 'foo' in 'field list'
4
set @a := connection_id() + 3;
5
select @a - connection_id();
12
CREATE TABLE t1 ( i int not null, v int not null,index (i));
13
insert into t1 values (1,1),(1,3),(2,1);
14
create table t2 (i int not null, unique (i));
15
insert into t2 select distinct i from t1;
20
select distinct t2.i,@vv1:=if(sv1.i,1,0),@vv2:=if(sv2.i,1,0),@vv3:=if(sv3.i,1,0), @vv1+@vv2+@vv3 from t2 left join t1 as sv1 on sv1.i=t2.i and sv1.v=1 left join t1 as sv2 on sv2.i=t2.i and sv2.v=2 left join t1 as sv3 on sv3.i=t2.i and sv3.v=3;
21
i @vv1:=if(sv1.i,1,0) @vv2:=if(sv2.i,1,0) @vv3:=if(sv3.i,1,0) @vv1+@vv2+@vv3
24
explain select * from t1 where i=@vv1;
25
id select_type table type possible_keys key key_len ref rows Extra
26
1 SIMPLE t1 ref i i 4 const 1
27
select @vv1,i,v from t1 where i=@vv1;
31
explain select * from t1 where @vv1:=@vv1+1 and i=@vv1;
32
id select_type table type possible_keys key key_len ref rows Extra
33
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where
34
explain select @vv1:=i from t1 where i=@vv1;
35
id select_type table type possible_keys key key_len ref rows Extra
36
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where
37
explain select * from t1 where i=@vv1;
38
id select_type table type possible_keys key key_len ref rows Extra
39
1 SIMPLE t1 ref i i 4 const 1
42
select @a:=10, @b:=1, @a > @b, @a < @b;
43
@a:=10 @b:=1 @a > @b @a < @b
45
select @a:="10", @b:="1", @a > @b, @a < @b;
46
@a:="10" @b:="1" @a > @b @a < @b
48
select @a:=10, @b:=2, @a > @b, @a < @b;
49
@a:=10 @b:=2 @a > @b @a < @b
51
select @a:="10", @b:="2", @a > @b, @a < @b;
52
@a:="10" @b:="2" @a > @b @a < @b
60
create table t1 (id int, d double, c char(10));
61
insert into t1 values (1,2.0, "test");
65
update t1 SET id=(@c:=@c+1);
72
update t1 set id=(@c:=@c+1);
82
select @d,(@d:=id),@d from t1;
85
select @e,(@e:=d),@e from t1;
88
select @f,(@f:=c),@f from t1;
92
select @g,(@g:=c),@g from t1;
95
select @c, @d, @e, @f;
98
select @d:=id, @e:=id, @f:=id, @g:=@id from t1;
99
@d:=id @e:=id @f:=id @g:=@id
101
select @c, @d, @e, @f, @g;
105
select @a:=10, @b:=2, @a>@b, @a:="10", @b:="2", @a>@b, @a:=10, @b:=2, @a>@b, @a:="10", @b:="2", @a>@b;
106
@a:=10 @b:=2 @a>@b @a:="10" @b:="2" @a>@b @a:=10 @b:=2 @a>@b @a:="10" @b:="2" @a>@b
107
10 2 1 10 2 1 10 2 1 10 2 1
108
create table t1 (i int not null);
109
insert t1 values (1),(2),(2),(3),(3),(3);
113
select @a, @a:=@a+count(*), count(*), @a from t1 group by i;
114
@a @a:=@a+count(*) count(*) @a
121
select @a+0, @a:=@a+0+count(*), count(*), @a+0 from t1 group by i;
122
@a+0 @a:=@a+0+count(*) count(*) @a+0
127
select @a,@a:="hello",@a,@a:=3,@a,@a:="hello again" from t1 group by i;
128
@a @a:="hello" @a @a:=3 @a @a:="hello again"
129
0 hello 0 3 0 hello again
130
0 hello 0 3 0 hello again
131
0 hello 0 3 0 hello again
132
select @a,@a:="hello",@a,@a:=3,@a,@a:="hello again" from t1 group by i;
133
@a @a:="hello" @a @a:=3 @a @a:="hello again"
134
hello again hello hello again 3 hello again hello again
135
hello again hello hello again 3 hello again hello again
136
hello again hello hello again 3 hello again hello again
139
select FIELD( @var,'1it','Hit') as my_column;
142
set session @honk=99;
143
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near '@honk=99' at line 1
144
select @@local.max_allowed_packet;
145
@@local.max_allowed_packet
147
select @@session.max_allowed_packet;
148
@@session.max_allowed_packet
150
select @@global.max_allowed_packet;
151
@@global.max_allowed_packet
153
select @@max_allowed_packet;
156
select @@Max_Allowed_Packet;
162
select @@global.version;
166
set @first_var= NULL;
167
create table t1 select @first_var;
168
show create table t1;
170
t1 CREATE TABLE `t1` (
172
) ENGINE=DEFAULT COLLATE = utf8_general_ci
174
set @first_var= cast(NULL as integer);
175
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'integer)' at line 1
176
set @first_var= NULL;
177
create table t1 select @first_var;
178
show create table t1;
180
t1 CREATE TABLE `t1` (
182
) ENGINE=DEFAULT COLLATE = utf8_general_ci
184
set @first_var= concat(NULL);
185
create table t1 select @first_var;
186
show create table t1;
188
t1 CREATE TABLE `t1` (
190
) ENGINE=DEFAULT COLLATE = utf8_general_ci
193
set @first_var= cast(NULL as CHAR);
194
create table t1 select @first_var;
195
show create table t1;
197
t1 CREATE TABLE `t1` (
198
`@first_var` TEXT COLLATE utf8_general_ci
199
) ENGINE=DEFAULT COLLATE = utf8_general_ci
201
set @a=18446744071710965857;
205
CREATE TABLE `bigfailure` (
206
`afield` BIGINT NOT NULL
208
INSERT INTO `bigfailure` VALUES (18446744071710965857);
209
SELECT * FROM bigfailure;
212
select * from (SELECT afield FROM bigfailure) as b;
215
select * from bigfailure where afield = (SELECT afield FROM bigfailure);
218
select * from bigfailure where afield = 18446744071710965857;
221
select * from bigfailure where afield = '18446744071710965857';
223
select * from bigfailure where afield = 18446744071710965856+1;
226
SET @a := (SELECT afield FROM bigfailure);
230
SET @a := (select afield from (SELECT afield FROM bigfailure) as b);
234
SET @a := (select * from bigfailure where afield = (SELECT afield FROM bigfailure));
238
drop table bigfailure;
239
create table t1(f1 int, f2 int);
240
insert into t1 values (1,2),(2,3),(3,1);
241
select @var:=f2 from t1 group by f1 order by f2 desc limit 1;
248
insert into city 'blah';
249
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near ''blah'' at line 1
250
SHOW COUNT(*) WARNINGS;
251
@@session.warning_count
253
SHOW COUNT(*) ERRORS;
254
@@session.error_count
256
create table t1(f1 int, f2 varchar(2), f3 float, f4 decimal(2,1));
257
insert into t1 values
258
(1, "a", 1.5, 1.6), (1, "a", 1.5, 1.6), (2, "b", 2.5, 2.6),
259
(3, "c", 3.5, 3.6), (4, "d", 4.5, 4.6), (1, "a", 1.5, 1.6),
260
(3, "c", 3.5, 3.6), (1, "a", 1.5, 1.6);
261
select @a:=f1, count(f1) from t1 group by 1 desc;
267
select @a:=f1, count(f1) from t1 group by 1 asc;
273
select @a:=f2, count(f2) from t1 group by 1 desc;
279
select @a:=f3, count(f3) from t1 group by 1 desc;
285
select @a:=f4, count(f4) from t1 group by 1 desc;
292
create table t1 (f1 int);
293
insert into t1 values (2), (1);
294
select @i := f1 as j from t1 order by 1;
299
create table t1(a int);
300
insert into t1 values(5),(4),(4),(3),(2),(2),(2),(1);
303
set @prev_score := NULL;
304
select @rownum := @rownum + 1 as row,
305
@rank := IF(@prev_score!=a, @rownum, @rank) as rank,
306
@prev_score := a as score
307
from t1 order by score desc;