mirror of
https://github.com/MariaDB/server.git
synced 2026-05-07 23:54:31 +02:00
- COLUMN_CREATE(column_nr, value, [column_nr,value]...) - COLUMN_ADD(blob,column_nr, value, column_nr,value]...) - COLUMN_DELETE(blob, column_nr, column_nr...) - COLUMN_EXISTS(blob, column_nr) - COLUMN_LIST(blob, column_nr) - COLUMN_GET(string, column_nr AS type) Added cast(X as DOUBLE) and cast(x as INT) Better warning and error messages for wrong cast's Created some sub functions to simplify and reuse code. Added a lot of conversation functions with error/warnings for what went wrong. Fixed some issues when casting time to datetime. Added functions to dynamic strings and Strings to allow one to move a string buffer from dynamic strings to String (to save malloc+ copy) Added dynamic columns library to libmysqlclient include/Makefile.am: Added ma_dyncol.h include/decimal.h: Added 'const' to arguments for some functions. include/my_sys.h: Added dynstr_reassociate() include/my_time.h: Added TIME_SUBSECOND_RANGE Added double_to_datetime() Added flag argument to str_to_time() libmysql/CMakeLists.txt: Added mysys/ma_dyncol.c libmysql/Makefile.shared: Added ma_dyncol libmysql/libmysql.c: Added argument to str_to_time() mysql-test/r/bigint.result: Better error messages mysql-test/r/cast.result: Better warning and error messages A lot of new cast() tests mysql-test/r/func_math.result: Better warning messages mysql-test/r/func_str.result: Better warning messages mysql-test/r/func_time.result: Better warning messages mysql-test/r/sp-vars.result: Better warning messages mysql-test/r/strict.result: Better warning messages New test result mysql-test/r/type_newdecimal.result: Better warning messages mysql-test/r/warnings.result: Better warning messages mysql-test/suite/funcs_1/r/innodb_func_view.result: Updated results after better cast warnings mysql-test/suite/funcs_1/r/memory_func_view.result: Updated results after better cast warnings mysql-test/suite/funcs_1/r/myisam_func_view.result: Updated results after better cast warnings mysql-test/suite/optimizer_unfixed_bugs/t/bug43448.test: Added begin...commit to speed up test. mysql-test/suite/parts/inc/part_supported_sql_funcs_delete.inc: Added begin...commit to speed up test. mysql-test/suite/parts/inc/partition_supported_sql_funcs.inc: Added begin...commit to speed up test. mysql-test/suite/parts/r/part_supported_sql_func_innodb.result: Added begin...commit to speed up test. mysql-test/suite/parts/r/part_supported_sql_func_myisam.result: Added begin...commit to speed up test. mysql-test/suite/parts/r/rpl_partition.result: Added begin...commit to speed up test. mysql-test/suite/parts/t/part_supported_sql_func_innodb.test: Removed duplicated --big_test mysql-test/suite/parts/t/rpl_partition.test: Added begin...commit to speed up test. mysql-test/suite/pbxt/r/cast.result: Updated results after better cast warnings mysql-test/suite/pbxt/r/func_str.result: Updated results after better cast warnings mysql-test/suite/pbxt/r/type_newdecimal.result: Updated results after better cast warnings mysql-test/suite/rpl/r/rpl_innodb_bug28430.result: Added begin...commit to speed up test. mysql-test/suite/rpl/t/rpl_innodb_bug28430.test: Added begin...commit to speed up test. mysql-test/suite/vcol/r/vcol_supported_sql_funcs_innodb.result: More warnings mysql-test/suite/vcol/r/vcol_supported_sql_funcs_myisam.result: More warnings mysql-test/t/cast.test: A lot of new cast() tests mysql-test/t/strict.test: Added new test mysys/CMakeLists.txt: Added ma_dyncol.c mysys/Makefile.am: Added ma_dyncol.c mysys/string.c: Added dynstr_reassociate() to move a buffer from dynamic_strings to some other allocator sql-common/my_time.c: Added 'fuzzydate' flag to str_to_time() Added support for microseconds to my_time_to_str() and my_datetime_to_str() Reset second_parts in number_to_datetime() Added double_to_datetime() sql/field.cc: Added double_to_longlong() and truncate_double() to simplify and reuse code sql/field.h: New prototypes sql/item.cc: Changed Item::get_date(MYSQL_TIME *ltime,uint fuzzydate) to be aware of type of argument. (Needed to make it microsecond safe and get better warnings). Updated call to str_to_time_with_warn() sql/item.h: Added struct st_dyncall_create_def used by dynamic columns Added virtual bool dynamic_result() to tell if type of argument may change over calls. sql/item_cmpfunc.cc: Added Item_func_dyncol_exists() sql/item_cmpfunc.h: Added class Item_func_dyncol_exists sql/item_create.cc: Added get_length_and_scale() to simplify other functions Simplified and extended create_func_cast() Added support for cast(X as double(X,Y)) Added functions to create dynamic column functions. sql/item_create.h: Added prototypes sql/item_func.cc: Extended cast functions Item_func_signed() and Item_func_unsigned() to work with dynamic types Added Item_double_typecast() sql/item_func.h: Added class Item_double_typecast() sql/item_strfunc.cc: Added functions for COLUMN_CREATE(), COLUMN_ADD(), COLUMN_GET() and COLUMN_LIST() sql/item_strfunc.h: Added classes for COLUMN_CREATE(), COLUMN_ADD(), COLUMN_GET() and COLUMN_LIST() sql/item_timefunc.cc: Added flag argument to str_to_time_with_warn() Updated Item_char_typecast() to handle result type that may change between calls (for dynamic columns) Added Item_time_typecast::get_date() to ensure that we cast a datetime to time properly. sql/item_timefunc.h: Added get_date() to Item_time_typecast() to allow proper results for casting time to datetime sql/lex.h: Added new SQL function names sql/my_decimal.cc: Added 'const' to some arguments. Better error message in case of errors (we now print out the wrong value) Added my_decimal2int() sql/my_decimal.h: Moved some constants to my_decimal_limits.h Updated prototypes. Made my_decimal2int() a function as it's rather long (no reason to have it inline) Added decimal2my_decimal() function. sql/mysql_priv.h: Prototypes for new functions sql/share/errmsg.txt: New error messages for wrong casts and dynamic columns sql/sql_acl.cc: Fixed indentation sql/sql_base.cc: Added dynamic_column_error_message() sql/sql_string.h: Added reassociate() to move a buffer to be owned by String object. sql/sql_yacc.yy: Added syntax for COLUMN_ functions. sql/time.cc: Updated str_to_datetime_with_warn() flag argument to same type as other functions Added conversion flag to str_to_time_with_warn() (Similar to all datetime functions) Added conversion functions with warnings: double_to_datetime_with_warn() and decimal_to_datetime_with_warn() strings/decimal.c: Added 'const' to arguments for some functions. unittest/mysys/Makefile.am: Added test for dynamic columns code
406 lines
13 KiB
Text
406 lines
13 KiB
Text
select CAST(1-2 AS UNSIGNED);
|
||
CAST(1-2 AS UNSIGNED)
|
||
18446744073709551615
|
||
Warnings:
|
||
Warning 1105 Cast to unsigned converted negative integer to it's positive complement
|
||
select CAST(CAST(1-2 AS UNSIGNED) AS SIGNED INTEGER);
|
||
CAST(CAST(1-2 AS UNSIGNED) AS SIGNED INTEGER)
|
||
-1
|
||
Warnings:
|
||
Warning 1105 Cast to unsigned converted negative integer to it's positive complement
|
||
select CAST('10 ' as unsigned integer);
|
||
CAST('10 ' as unsigned integer)
|
||
10
|
||
Warnings:
|
||
Warning 1292 Truncated incorrect INTEGER value: '10 '
|
||
select cast(-5 as unsigned) | 1, cast(-5 as unsigned) & -1;
|
||
cast(-5 as unsigned) | 1 cast(-5 as unsigned) & -1
|
||
18446744073709551611 18446744073709551611
|
||
Warnings:
|
||
Warning 1105 Cast to unsigned converted negative integer to it's positive complement
|
||
Warning 1105 Cast to unsigned converted negative integer to it's positive complement
|
||
select cast(-5 as unsigned) -1, cast(-5 as unsigned) + 1;
|
||
cast(-5 as unsigned) -1 cast(-5 as unsigned) + 1
|
||
18446744073709551610 18446744073709551612
|
||
Warnings:
|
||
Warning 1105 Cast to unsigned converted negative integer to it's positive complement
|
||
Warning 1105 Cast to unsigned converted negative integer to it's positive complement
|
||
select ~5, cast(~5 as signed);
|
||
~5 cast(~5 as signed)
|
||
18446744073709551610 -6
|
||
explain extended select ~5, cast(~5 as signed);
|
||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
|
||
Warnings:
|
||
Note 1003 select ~(5) AS `~5`,cast(~(5) as signed) AS `cast(~5 as signed)`
|
||
select cast(5 as unsigned) -6.0;
|
||
cast(5 as unsigned) -6.0
|
||
-1.0
|
||
select cast(NULL as signed), cast(1/0 as signed);
|
||
cast(NULL as signed) cast(1/0 as signed)
|
||
NULL NULL
|
||
select cast(NULL as unsigned), cast(1/0 as unsigned);
|
||
cast(NULL as unsigned) cast(1/0 as unsigned)
|
||
NULL NULL
|
||
select cast("A" as binary) = "a", cast(BINARY "a" as CHAR) = "A";
|
||
cast("A" as binary) = "a" cast(BINARY "a" as CHAR) = "A"
|
||
0 1
|
||
select cast("2001-1-1" as DATE), cast("2001-1-1" as DATETIME);
|
||
cast("2001-1-1" as DATE) cast("2001-1-1" as DATETIME)
|
||
2001-01-01 2001-01-01 00:00:00
|
||
select cast("1:2:3" as TIME);
|
||
cast("1:2:3" as TIME)
|
||
01:02:03
|
||
select CONVERT("2004-01-22 21:45:33",DATE);
|
||
CONVERT("2004-01-22 21:45:33",DATE)
|
||
2004-01-22
|
||
select 10+'10';
|
||
10+'10'
|
||
20
|
||
select 10.0+'10';
|
||
10.0+'10'
|
||
20
|
||
select 10E+0+'10';
|
||
10E+0+'10'
|
||
20
|
||
select CONVERT(DATE "2004-01-22 21:45:33" USING latin1);
|
||
CONVERT(DATE "2004-01-22 21:45:33" USING latin1)
|
||
2004-01-22 21:45:33
|
||
select CONVERT(DATE "2004-01-22 21:45:33",CHAR);
|
||
CONVERT(DATE "2004-01-22 21:45:33",CHAR)
|
||
2004-01-22 21:45:33
|
||
select CONVERT(DATE "2004-01-22 21:45:33",CHAR(4));
|
||
CONVERT(DATE "2004-01-22 21:45:33",CHAR(4))
|
||
2004
|
||
Warnings:
|
||
Warning 1292 Truncated incorrect CHAR(4) value: '2004-01-22 21:45:33'
|
||
select CONVERT(DATE "2004-01-22 21:45:33",BINARY(4));
|
||
CONVERT(DATE "2004-01-22 21:45:33",BINARY(4))
|
||
2004
|
||
Warnings:
|
||
Warning 1292 Truncated incorrect BINARY(4) value: '2004-01-22 21:45:33'
|
||
select CAST(DATE "2004-01-22 21:45:33" AS BINARY(4));
|
||
CAST(DATE "2004-01-22 21:45:33" AS BINARY(4))
|
||
2004
|
||
Warnings:
|
||
Warning 1292 Truncated incorrect BINARY(4) value: '2004-01-22 21:45:33'
|
||
select CAST(0xb3 as signed);
|
||
CAST(0xb3 as signed)
|
||
179
|
||
select CAST(0x8fffffffffffffff as signed);
|
||
CAST(0x8fffffffffffffff as signed)
|
||
-8070450532247928833
|
||
select CAST(0xffffffffffffffff as unsigned);
|
||
CAST(0xffffffffffffffff as unsigned)
|
||
18446744073709551615
|
||
select CAST(0xfffffffffffffffe as signed);
|
||
CAST(0xfffffffffffffffe as signed)
|
||
-2
|
||
select cast('-10a' as signed integer);
|
||
cast('-10a' as signed integer)
|
||
-10
|
||
Warnings:
|
||
Warning 1292 Truncated incorrect INTEGER value: '-10a'
|
||
select cast('a10' as unsigned integer);
|
||
cast('a10' as unsigned integer)
|
||
0
|
||
Warnings:
|
||
Warning 1292 Truncated incorrect INTEGER value: 'a10'
|
||
select 10+'a';
|
||
10+'a'
|
||
10
|
||
Warnings:
|
||
Warning 1292 Truncated incorrect DOUBLE value: 'a'
|
||
select 10.0+cast('a' as decimal);
|
||
10.0+cast('a' as decimal)
|
||
10.0
|
||
Warnings:
|
||
Warning 1292 Truncated incorrect DECIMAL value: 'a'
|
||
select 10E+0+'a';
|
||
10E+0+'a'
|
||
10
|
||
Warnings:
|
||
Warning 1292 Truncated incorrect DOUBLE value: 'a'
|
||
select cast('18446744073709551616' as unsigned);
|
||
cast('18446744073709551616' as unsigned)
|
||
18446744073709551615
|
||
Warnings:
|
||
Warning 1292 Truncated incorrect INTEGER value: '18446744073709551616'
|
||
select cast('18446744073709551616' as signed);
|
||
cast('18446744073709551616' as signed)
|
||
-1
|
||
Warnings:
|
||
Warning 1292 Truncated incorrect INTEGER value: '18446744073709551616'
|
||
select cast('9223372036854775809' as signed);
|
||
cast('9223372036854775809' as signed)
|
||
-9223372036854775807
|
||
Warnings:
|
||
Warning 1105 Cast to signed converted positive out-of-range integer to it's negative complement
|
||
select cast('-1' as unsigned);
|
||
cast('-1' as unsigned)
|
||
18446744073709551615
|
||
Warnings:
|
||
Warning 1105 Cast to unsigned converted negative integer to it's positive complement
|
||
select cast('abc' as signed);
|
||
cast('abc' as signed)
|
||
0
|
||
Warnings:
|
||
Warning 1292 Truncated incorrect INTEGER value: 'abc'
|
||
select cast('1a' as signed);
|
||
cast('1a' as signed)
|
||
1
|
||
Warnings:
|
||
Warning 1292 Truncated incorrect INTEGER value: '1a'
|
||
select cast('' as signed);
|
||
cast('' as signed)
|
||
0
|
||
Warnings:
|
||
Warning 1292 Truncated incorrect INTEGER value: ''
|
||
set names binary;
|
||
select cast(_latin1'test' as char character set latin2);
|
||
cast(_latin1'test' as char character set latin2)
|
||
test
|
||
select cast(_koi8r'<27><><EFBFBD><EFBFBD>' as char character set cp1251);
|
||
cast(_koi8r'<27><><EFBFBD><EFBFBD>' as char character set cp1251)
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
create table t1 select cast(_koi8r'<27><><EFBFBD><EFBFBD>' as char character set cp1251) as t;
|
||
show create table t1;
|
||
Table Create Table
|
||
t1 CREATE TABLE `t1` (
|
||
`t` varchar(4) CHARACTER SET cp1251 NOT NULL DEFAULT ''
|
||
) ENGINE=PBXT DEFAULT CHARSET=latin1
|
||
drop table t1;
|
||
select
|
||
cast(_latin1'ab' AS char) as c1,
|
||
cast(_latin1'a ' AS char) as c2,
|
||
cast(_latin1'abc' AS char(2)) as c3,
|
||
cast(_latin1'a ' AS char(2)) as c4,
|
||
hex(cast(_latin1'a' AS char(2))) as c5;
|
||
c1 c2 c3 c4 c5
|
||
ab a ab a 6100
|
||
Warnings:
|
||
Warning 1292 Truncated incorrect BINARY(2) value: 'abc'
|
||
Warning 1292 Truncated incorrect BINARY(2) value: 'a '
|
||
select cast(1000 as CHAR(3));
|
||
cast(1000 as CHAR(3))
|
||
100
|
||
Warnings:
|
||
Warning 1292 Truncated incorrect BINARY(3) value: '1000'
|
||
create table t1 select
|
||
cast(_latin1'ab' AS char) as c1,
|
||
cast(_latin1'a ' AS char) as c2,
|
||
cast(_latin1'abc' AS char(2)) as c3,
|
||
cast(_latin1'a ' AS char(2)) as c4,
|
||
cast(_latin1'a' AS char(2)) as c5;
|
||
Warnings:
|
||
Warning 1292 Truncated incorrect BINARY(2) value: 'abc'
|
||
Warning 1292 Truncated incorrect BINARY(2) value: 'a '
|
||
select c1,c2,c3,c4,hex(c5) from t1;
|
||
c1 c2 c3 c4 hex(c5)
|
||
ab a ab a 6100
|
||
show create table t1;
|
||
Table Create Table
|
||
t1 CREATE TABLE `t1` (
|
||
`c1` varbinary(2) NOT NULL DEFAULT '',
|
||
`c2` varbinary(2) NOT NULL DEFAULT '',
|
||
`c3` varbinary(2) NOT NULL DEFAULT '',
|
||
`c4` varbinary(2) NOT NULL DEFAULT '',
|
||
`c5` varbinary(2) NOT NULL DEFAULT ''
|
||
) ENGINE=PBXT DEFAULT CHARSET=latin1
|
||
drop table t1;
|
||
select
|
||
cast(_koi8r'<27><>' AS nchar) as c1,
|
||
cast(_koi8r'<27> ' AS nchar) as c2,
|
||
cast(_koi8r'<27><><EFBFBD>' AS nchar(2)) as c3,
|
||
cast(_koi8r'<27> ' AS nchar(2)) as c4,
|
||
cast(_koi8r'<27>' AS nchar(2)) as c5;
|
||
c1 c2 c3 c4 c5
|
||
фг ф фг ф ф
|
||
Warnings:
|
||
Warning 1292 Truncated incorrect CHAR(4) value: 'фгх'
|
||
Warning 1292 Truncated incorrect CHAR(3) value: 'ф '
|
||
create table t1 select
|
||
cast(_koi8r'<27><>' AS nchar) as c1,
|
||
cast(_koi8r'<27> ' AS nchar) as c2,
|
||
cast(_koi8r'<27><><EFBFBD>' AS nchar(2)) as c3,
|
||
cast(_koi8r'<27> ' AS nchar(2)) as c4,
|
||
cast(_koi8r'<27>' AS nchar(2)) as c5;
|
||
Warnings:
|
||
Warning 1292 Truncated incorrect CHAR(4) value: 'фгх'
|
||
Warning 1292 Truncated incorrect CHAR(3) value: 'ф '
|
||
select * from t1;
|
||
c1 c2 c3 c4 c5
|
||
фг ф фг ф ф
|
||
show create table t1;
|
||
Table Create Table
|
||
t1 CREATE TABLE `t1` (
|
||
`c1` varchar(2) CHARACTER SET utf8 NOT NULL DEFAULT '',
|
||
`c2` varchar(2) CHARACTER SET utf8 NOT NULL DEFAULT '',
|
||
`c3` varchar(2) CHARACTER SET utf8 NOT NULL DEFAULT '',
|
||
`c4` varchar(2) CHARACTER SET utf8 NOT NULL DEFAULT '',
|
||
`c5` varchar(2) CHARACTER SET utf8 NOT NULL DEFAULT ''
|
||
) ENGINE=PBXT DEFAULT CHARSET=latin1
|
||
drop table t1;
|
||
create table t1 (a binary(4), b char(4) character set koi8r);
|
||
insert into t1 values (_binary'<27><><EFBFBD><EFBFBD>',_binary'<27><><EFBFBD><EFBFBD>');
|
||
select a,b,cast(a as char character set cp1251),cast(b as binary) from t1;
|
||
a b cast(a as char character set cp1251) cast(b as binary)
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <09><><EFBFBD><EFBFBD> <09><><EFBFBD><EFBFBD> <09><><EFBFBD><EFBFBD>
|
||
set names koi8r;
|
||
select a,b,cast(a as char character set cp1251),cast(b as binary) from t1;
|
||
a b cast(a as char character set cp1251) cast(b as binary)
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <09><><EFBFBD><EFBFBD> <09><><EFBFBD><EFBFBD> <09><><EFBFBD><EFBFBD>
|
||
set names cp1251;
|
||
select a,b,cast(a as char character set cp1251),cast(b as binary) from t1;
|
||
a b cast(a as char character set cp1251) cast(b as binary)
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <09><><EFBFBD><EFBFBD> <09><><EFBFBD><EFBFBD> <09><><EFBFBD><EFBFBD>
|
||
drop table t1;
|
||
set names binary;
|
||
select cast("2001-1-1" as date) = "2001-01-01";
|
||
cast("2001-1-1" as date) = "2001-01-01"
|
||
1
|
||
select cast("2001-1-1" as datetime) = "2001-01-01 00:00:00";
|
||
cast("2001-1-1" as datetime) = "2001-01-01 00:00:00"
|
||
1
|
||
select cast("1:2:3" as TIME) = "1:02:03";
|
||
cast("1:2:3" as TIME) = "1:02:03"
|
||
0
|
||
select cast(NULL as DATE);
|
||
cast(NULL as DATE)
|
||
NULL
|
||
select cast(NULL as BINARY);
|
||
cast(NULL as BINARY)
|
||
NULL
|
||
CREATE TABLE t1 (a enum ('aac','aab','aaa') not null);
|
||
INSERT INTO t1 VALUES ('aaa'),('aab'),('aac');
|
||
SELECT a, CAST(a AS CHAR) FROM t1 ORDER BY CAST(a AS UNSIGNED) ;
|
||
a CAST(a AS CHAR)
|
||
aac aac
|
||
aab aab
|
||
aaa aaa
|
||
SELECT a, CAST(a AS CHAR(3)) FROM t1 ORDER BY CAST(a AS CHAR(2)), a;
|
||
a CAST(a AS CHAR(3))
|
||
aac aac
|
||
aab aab
|
||
aaa aaa
|
||
Warnings:
|
||
Warning 1292 Truncated incorrect BINARY(2) value: 'aaa'
|
||
Warning 1292 Truncated incorrect BINARY(2) value: 'aab'
|
||
Warning 1292 Truncated incorrect BINARY(2) value: 'aac'
|
||
SELECT a, CAST(a AS UNSIGNED) FROM t1 ORDER BY CAST(a AS CHAR) ;
|
||
a CAST(a AS UNSIGNED)
|
||
aaa 3
|
||
aab 2
|
||
aac 1
|
||
SELECT a, CAST(a AS CHAR(2)) FROM t1 ORDER BY CAST(a AS CHAR(3)), a;
|
||
a CAST(a AS CHAR(2))
|
||
aaa aa
|
||
aab aa
|
||
aac aa
|
||
Warnings:
|
||
Warning 1292 Truncated incorrect BINARY(2) value: 'aaa'
|
||
Warning 1292 Truncated incorrect BINARY(2) value: 'aab'
|
||
Warning 1292 Truncated incorrect BINARY(2) value: 'aac'
|
||
DROP TABLE t1;
|
||
select date_add(cast('2004-12-30 12:00:00' as date), interval 0 hour);
|
||
date_add(cast('2004-12-30 12:00:00' as date), interval 0 hour)
|
||
2004-12-30 00:00:00
|
||
select timediff(cast('2004-12-30 12:00:00' as time), '12:00:00');
|
||
timediff(cast('2004-12-30 12:00:00' as time), '12:00:00')
|
||
00:00:00
|
||
select timediff(cast('1 12:00:00' as time), '12:00:00');
|
||
timediff(cast('1 12:00:00' as time), '12:00:00')
|
||
24:00:00
|
||
select cast(18446744073709551615 as unsigned);
|
||
cast(18446744073709551615 as unsigned)
|
||
18446744073709551615
|
||
select cast(18446744073709551615 as signed);
|
||
cast(18446744073709551615 as signed)
|
||
-1
|
||
select cast('18446744073709551615' as unsigned);
|
||
cast('18446744073709551615' as unsigned)
|
||
18446744073709551615
|
||
select cast('18446744073709551615' as signed);
|
||
cast('18446744073709551615' as signed)
|
||
-1
|
||
Warnings:
|
||
Warning 1105 Cast to signed converted positive out-of-range integer to it's negative complement
|
||
select cast('9223372036854775807' as signed);
|
||
cast('9223372036854775807' as signed)
|
||
9223372036854775807
|
||
select cast(concat('184467440','73709551615') as unsigned);
|
||
cast(concat('184467440','73709551615') as unsigned)
|
||
18446744073709551615
|
||
select cast(concat('184467440','73709551615') as signed);
|
||
cast(concat('184467440','73709551615') as signed)
|
||
-1
|
||
Warnings:
|
||
Warning 1105 Cast to signed converted positive out-of-range integer to it's negative complement
|
||
select cast(repeat('1',20) as unsigned);
|
||
cast(repeat('1',20) as unsigned)
|
||
11111111111111111111
|
||
select cast(repeat('1',20) as signed);
|
||
cast(repeat('1',20) as signed)
|
||
-7335632962598440505
|
||
Warnings:
|
||
Warning 1105 Cast to signed converted positive out-of-range integer to it's negative complement
|
||
select cast(1.0e+300 as signed int);
|
||
cast(1.0e+300 as signed int)
|
||
9223372036854775807
|
||
CREATE TABLE t1 (f1 double);
|
||
INSERT INTO t1 SET f1 = -1.0e+30 ;
|
||
INSERT INTO t1 SET f1 = +1.0e+30 ;
|
||
SELECT f1 AS double_val, CAST(f1 AS SIGNED INT) AS cast_val FROM t1;
|
||
double_val cast_val
|
||
-1e+30 -9223372036854775808
|
||
1e+30 9223372036854775807
|
||
Warnings:
|
||
Warning 1292 Truncated incorrect INTEGER value: '-1e+30'
|
||
Warning 1292 Truncated incorrect INTEGER value: '1e+30'
|
||
DROP TABLE t1;
|
||
select cast('1.2' as decimal(3,2));
|
||
cast('1.2' as decimal(3,2))
|
||
1.20
|
||
select 1e18 * cast('1.2' as decimal(3,2));
|
||
1e18 * cast('1.2' as decimal(3,2))
|
||
1.2e+18
|
||
select cast(cast('1.2' as decimal(3,2)) as signed);
|
||
cast(cast('1.2' as decimal(3,2)) as signed)
|
||
1
|
||
set @v1=1e18;
|
||
select cast(@v1 as decimal(22, 2));
|
||
cast(@v1 as decimal(22, 2))
|
||
1000000000000000000.00
|
||
select cast(-1e18 as decimal(22,2));
|
||
cast(-1e18 as decimal(22,2))
|
||
-1000000000000000000.00
|
||
create table t1(s1 time);
|
||
insert into t1 values ('11:11:11');
|
||
select cast(s1 as decimal(7,2)) from t1;
|
||
cast(s1 as decimal(7,2))
|
||
99999.99
|
||
Warnings:
|
||
Error 1264 Out of range value for column 'cast(s1 as decimal(7,2))' at row 1
|
||
drop table t1;
|
||
CREATE TABLE t1 (v varchar(10), tt tinytext, t text,
|
||
mt mediumtext, lt longtext);
|
||
INSERT INTO t1 VALUES ('1.01', '2.02', '3.03', '4.04', '5.05');
|
||
SELECT CAST(v AS DECIMAL), CAST(tt AS DECIMAL), CAST(t AS DECIMAL),
|
||
CAST(mt AS DECIMAL), CAST(lt AS DECIMAL) from t1;
|
||
CAST(v AS DECIMAL) CAST(tt AS DECIMAL) CAST(t AS DECIMAL) CAST(mt AS DECIMAL) CAST(lt AS DECIMAL)
|
||
1 2 3 4 5
|
||
DROP TABLE t1;
|
||
select cast(NULL as decimal(6)) as t1;
|
||
t1
|
||
NULL
|
||
set names latin1;
|
||
select hex(cast('a' as char(2) binary));
|
||
hex(cast('a' as char(2) binary))
|
||
61
|
||
select hex(cast('a' as binary(2)));
|
||
hex(cast('a' as binary(2)))
|
||
6100
|
||
select hex(cast('a' as char(2) binary));
|
||
hex(cast('a' as char(2) binary))
|
||
61
|
||
End of 5.0 tests
|