1
select CAST(1-2 AS UNSIGNED);
4
select CAST(CAST(1-2 AS UNSIGNED) AS SIGNED INTEGER);
5
CAST(CAST(1-2 AS UNSIGNED) AS SIGNED INTEGER)
7
select CAST('10 ' as unsigned integer);
8
CAST('10 ' as unsigned integer)
11
Warning 1292 Truncated incorrect INTEGER value: '10 '
12
select cast(-5 as unsigned) | 1, cast(-5 as unsigned) & -1;
13
cast(-5 as unsigned) | 1 cast(-5 as unsigned) & -1
14
18446744073709551611 18446744073709551611
15
select cast(-5 as unsigned) -1, cast(-5 as unsigned) + 1;
16
cast(-5 as unsigned) -1 cast(-5 as unsigned) + 1
17
18446744073709551610 18446744073709551612
18
select ~5, cast(~5 as signed);
20
18446744073709551610 -6
21
explain extended select ~5, cast(~5 as signed);
22
id select_type table type possible_keys key key_len ref rows filtered Extra
23
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
25
Note 1003 select ~(5) AS `~5`,cast(~(5) as signed) AS `cast(~5 as signed)`
26
select cast(5 as unsigned) -6.0;
27
cast(5 as unsigned) -6.0
29
select cast(NULL as signed), cast(1/0 as signed);
30
cast(NULL as signed) cast(1/0 as signed)
32
select cast(NULL as unsigned), cast(1/0 as unsigned);
33
cast(NULL as unsigned) cast(1/0 as unsigned)
35
1
select cast("A" as binary) = "a", cast(BINARY "a" as CHAR) = "A";
36
2
cast("A" as binary) = "a" cast(BINARY "a" as CHAR) = "A"
113
54
Warning 1292 Truncated incorrect DOUBLE value: 'a'
114
select cast('18446744073709551616' as unsigned);
115
cast('18446744073709551616' as unsigned)
118
Warning 1292 Truncated incorrect INTEGER value: '18446744073709551616'
119
select cast('18446744073709551616' as signed);
120
cast('18446744073709551616' as signed)
123
Warning 1292 Truncated incorrect INTEGER value: '18446744073709551616'
124
select cast('9223372036854775809' as signed);
125
cast('9223372036854775809' as signed)
128
Warning 1105 Cast to signed converted positive out-of-range integer to it's negative complement
129
select cast('-1' as unsigned);
130
cast('-1' as unsigned)
133
Warning 1105 Cast to unsigned converted negative integer to it's positive complement
134
select cast('abc' as signed);
135
cast('abc' as signed)
138
Warning 1292 Truncated incorrect INTEGER value: 'abc'
139
select cast('1a' as signed);
143
Warning 1292 Truncated incorrect INTEGER value: '1a'
144
select cast('' as signed);
148
Warning 1292 Truncated incorrect INTEGER value: ''
150
select cast(_latin1'test' as char character set latin2);
151
cast(_latin1'test' as char character set latin2)
153
select cast(_koi8r'����' as char character set cp1251);
154
cast(_koi8r'����' as char character set cp1251)
156
create table t1 select cast(_koi8r'����' as char character set cp1251) as t;
157
show create table t1;
159
t1 CREATE TABLE `t1` (
160
`t` varchar(4) CHARACTER SET cp1251 NOT NULL DEFAULT ''
161
) ENGINE=MyISAM DEFAULT CHARSET=latin1
164
cast(_latin1'ab' AS char) as c1,
165
cast(_latin1'a ' AS char) as c2,
166
cast(_latin1'abc' AS char(2)) as c3,
167
cast(_latin1'a ' AS char(2)) as c4,
168
hex(cast(_latin1'a' AS char(2))) as c5;
56
cast('ab' AS char) as c1,
57
cast('a ' AS char) as c2,
58
cast('abc' AS char(2)) as c3,
59
cast('a ' AS char(2)) as c4,
60
hex(cast('a' AS char(2))) as c5;
172
Warning 1292 Truncated incorrect BINARY(2) value: 'abc'
173
Warning 1292 Truncated incorrect BINARY(2) value: 'a '
64
Warning 1292 Truncated incorrect CHAR(2) value: 'abc'
65
Warning 1292 Truncated incorrect CHAR(2) value: 'a '
174
66
select cast(1000 as CHAR(3));
175
67
cast(1000 as CHAR(3))
178
Warning 1292 Truncated incorrect BINARY(3) value: '1000'
70
Warning 1292 Truncated incorrect CHAR(3) value: '1000'
179
71
create table t1 select
180
cast(_latin1'ab' AS char) as c1,
181
cast(_latin1'a ' AS char) as c2,
182
cast(_latin1'abc' AS char(2)) as c3,
183
cast(_latin1'a ' AS char(2)) as c4,
184
cast(_latin1'a' AS char(2)) as c5;
186
Warning 1292 Truncated incorrect BINARY(2) value: 'abc'
187
Warning 1292 Truncated incorrect BINARY(2) value: 'a '
188
select c1,c2,c3,c4,hex(c5) from t1;
191
show create table t1;
193
t1 CREATE TABLE `t1` (
194
`c1` varbinary(2) NOT NULL DEFAULT '',
195
`c2` varbinary(2) NOT NULL DEFAULT '',
196
`c3` varbinary(2) NOT NULL DEFAULT '',
197
`c4` varbinary(2) NOT NULL DEFAULT '',
198
`c5` varbinary(2) NOT NULL DEFAULT ''
199
) ENGINE=MyISAM DEFAULT CHARSET=latin1
72
cast('ab' AS char) as c1,
73
cast('a ' AS char) as c2,
74
cast('abc' AS char(2)) as c3,
75
cast('a ' AS char(2)) as c4,
76
cast('a' AS char(2)) as c5;
77
ERROR 22007: Truncated incorrect CHAR(2) value: 'abc'
202
cast(_koi8r'��' AS nchar) as c1,
203
cast(_koi8r'� ' AS nchar) as c2,
204
cast(_koi8r'���' AS nchar(2)) as c3,
205
cast(_koi8r'� ' AS nchar(2)) as c4,
206
cast(_koi8r'�' AS nchar(2)) as c5;
210
Warning 1292 Truncated incorrect CHAR(4) value: 'фгх'
211
Warning 1292 Truncated incorrect CHAR(3) value: 'ф '
212
create table t1 select
213
cast(_koi8r'��' AS nchar) as c1,
214
cast(_koi8r'� ' AS nchar) as c2,
215
cast(_koi8r'���' AS nchar(2)) as c3,
216
cast(_koi8r'� ' AS nchar(2)) as c4,
217
cast(_koi8r'�' AS nchar(2)) as c5;
219
Warning 1292 Truncated incorrect CHAR(4) value: 'фгх'
220
Warning 1292 Truncated incorrect CHAR(3) value: 'ф '
224
show create table t1;
226
t1 CREATE TABLE `t1` (
227
`c1` varchar(2) CHARACTER SET utf8 NOT NULL DEFAULT '',
228
`c2` varchar(2) CHARACTER SET utf8 NOT NULL DEFAULT '',
229
`c3` varchar(2) CHARACTER SET utf8 NOT NULL DEFAULT '',
230
`c4` varchar(2) CHARACTER SET utf8 NOT NULL DEFAULT '',
231
`c5` varchar(2) CHARACTER SET utf8 NOT NULL DEFAULT ''
232
) ENGINE=MyISAM DEFAULT CHARSET=latin1
234
create table t1 (a binary(4), b char(4) character set koi8r);
235
insert into t1 values (_binary'����',_binary'����');
236
select a,b,cast(a as char character set cp1251),cast(b as binary) from t1;
237
a b cast(a as char character set cp1251) cast(b as binary)
240
select a,b,cast(a as char character set cp1251),cast(b as binary) from t1;
241
a b cast(a as char character set cp1251) cast(b as binary)
244
select a,b,cast(a as char character set cp1251),cast(b as binary) from t1;
245
a b cast(a as char character set cp1251) cast(b as binary)
79
cast('��' AS char) as c1,
80
cast('� ' AS char) as c2,
81
cast('���' AS char(2)) as c3,
82
cast('� ' AS char(2)) as c4,
83
cast('�' AS char(2)) as c5;
87
Warning 1292 Truncated incorrect CHAR(2) value: '���'
88
Warning 1292 Truncated incorrect CHAR(2) value: '� '
249
89
select cast("2001-1-1" as date) = "2001-01-01";
250
90
cast("2001-1-1" as date) = "2001-01-01"
264
104
CREATE TABLE t1 (a enum ('aac','aab','aaa') not null);
265
105
INSERT INTO t1 VALUES ('aaa'),('aab'),('aac');
266
SELECT a, CAST(a AS CHAR) FROM t1 ORDER BY CAST(a AS UNSIGNED) ;
271
106
SELECT a, CAST(a AS CHAR(3)) FROM t1 ORDER BY CAST(a AS CHAR(2)), a;
272
107
a CAST(a AS CHAR(3))
277
Warning 1292 Truncated incorrect BINARY(2) value: 'aaa'
278
Warning 1292 Truncated incorrect BINARY(2) value: 'aab'
279
Warning 1292 Truncated incorrect BINARY(2) value: 'aac'
280
SELECT a, CAST(a AS UNSIGNED) FROM t1 ORDER BY CAST(a AS CHAR) ;
281
a CAST(a AS UNSIGNED)
112
Warning 1292 Truncated incorrect CHAR(2) value: 'aaa'
113
Warning 1292 Truncated incorrect CHAR(2) value: 'aab'
114
Warning 1292 Truncated incorrect CHAR(2) value: 'aac'
285
115
SELECT a, CAST(a AS CHAR(2)) FROM t1 ORDER BY CAST(a AS CHAR(3)), a;
286
116
a CAST(a AS CHAR(2))
291
Warning 1292 Truncated incorrect BINARY(2) value: 'aaa'
292
Warning 1292 Truncated incorrect BINARY(2) value: 'aab'
293
Warning 1292 Truncated incorrect BINARY(2) value: 'aac'
121
Warning 1292 Truncated incorrect CHAR(2) value: 'aaa'
122
Warning 1292 Truncated incorrect CHAR(2) value: 'aab'
123
Warning 1292 Truncated incorrect CHAR(2) value: 'aac'
295
125
select date_add(cast('2004-12-30 12:00:00' as date), interval 0 hour);
296
126
date_add(cast('2004-12-30 12:00:00' as date), interval 0 hour)
301
131
select timediff(cast('1 12:00:00' as time), '12:00:00');
302
132
timediff(cast('1 12:00:00' as time), '12:00:00')
304
select cast(18446744073709551615 as unsigned);
305
cast(18446744073709551615 as unsigned)
307
select cast(18446744073709551615 as signed);
308
cast(18446744073709551615 as signed)
310
select cast('18446744073709551615' as unsigned);
311
cast('18446744073709551615' as unsigned)
313
select cast('18446744073709551615' as signed);
314
cast('18446744073709551615' as signed)
317
Warning 1105 Cast to signed converted positive out-of-range integer to it's negative complement
318
select cast('9223372036854775807' as signed);
319
cast('9223372036854775807' as signed)
321
select cast(concat('184467440','73709551615') as unsigned);
322
cast(concat('184467440','73709551615') as unsigned)
324
select cast(concat('184467440','73709551615') as signed);
325
cast(concat('184467440','73709551615') as signed)
328
Warning 1105 Cast to signed converted positive out-of-range integer to it's negative complement
329
select cast(repeat('1',20) as unsigned);
330
cast(repeat('1',20) as unsigned)
332
select cast(repeat('1',20) as signed);
333
cast(repeat('1',20) as signed)
336
Warning 1105 Cast to signed converted positive out-of-range integer to it's negative complement
337
select cast(1.0e+300 as signed int);
338
cast(1.0e+300 as signed int)
340
CREATE TABLE t1 (f1 double);
341
INSERT INTO t1 SET f1 = -1.0e+30 ;
342
INSERT INTO t1 SET f1 = +1.0e+30 ;
343
SELECT f1 AS double_val, CAST(f1 AS SIGNED INT) AS cast_val FROM t1;
345
-1e30 -9223372036854775808
346
1e30 9223372036854775807
348
Warning 1292 Truncated incorrect INTEGER value: '-1e30'
349
Warning 1292 Truncated incorrect INTEGER value: '1e30'
351
134
select isnull(date(NULL)), isnull(cast(NULL as DATE));
352
135
isnull(date(NULL)) isnull(cast(NULL as DATE))
354
SELECT CAST(cast('01-01-01' as date) AS UNSIGNED);
355
CAST(cast('01-01-01' as date) AS UNSIGNED)
357
SELECT CAST(cast('01-01-01' as date) AS SIGNED);
358
CAST(cast('01-01-01' as date) AS SIGNED)
361
137
select cast('1.2' as decimal(3,2));
362
138
cast('1.2' as decimal(3,2))
364
140
select 1e18 * cast('1.2' as decimal(3,2));
365
141
1e18 * cast('1.2' as decimal(3,2))
367
select cast(cast('1.2' as decimal(3,2)) as signed);
368
cast(cast('1.2' as decimal(3,2)) as signed)
371
144
select cast(@v1 as decimal(22, 2));
372
145
cast(@v1 as decimal(22, 2))