2002-11-24 15:47:19 +02:00
|
|
|
|
#
|
|
|
|
|
# Test of cast function
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
select CAST(1-2 AS UNSIGNED);
|
|
|
|
|
select CAST(CAST(1-2 AS UNSIGNED) AS SIGNED INTEGER);
|
|
|
|
|
select CONVERT('-1',UNSIGNED);
|
|
|
|
|
select cast(-5 as unsigned) | 1, cast(-5 as unsigned) & -1;
|
|
|
|
|
select cast(-5 as unsigned) -1, cast(-5 as unsigned) + 1;
|
|
|
|
|
select ~5, cast(~5 as signed);
|
|
|
|
|
select cast(5 as unsigned) -6.0;
|
|
|
|
|
select cast("A" as binary) = "a", cast(BINARY "a" as CHAR) = "A";
|
|
|
|
|
select cast("2001-1-1" as DATE), cast("2001-1-1" as DATETIME);
|
|
|
|
|
select cast("1:2:3" as TIME);
|
|
|
|
|
|
2003-05-28 17:57:58 +05:00
|
|
|
|
#
|
|
|
|
|
# Character set convertion
|
|
|
|
|
#
|
2003-05-30 23:09:35 +05:00
|
|
|
|
set names binary;
|
2003-05-28 17:57:58 +05:00
|
|
|
|
select cast(_latin1'test' as char character set latin2);
|
|
|
|
|
select cast(_koi8r'<27><><EFBFBD><EFBFBD>' as char character set cp1251);
|
|
|
|
|
create table t1 select cast(_koi8r'<27><><EFBFBD><EFBFBD>' as char character set cp1251) as t;
|
|
|
|
|
show create table t1;
|
|
|
|
|
drop table t1;
|
|
|
|
|
|
2003-08-21 14:15:25 +05:00
|
|
|
|
#
|
|
|
|
|
# CAST to CHAR with/without length
|
|
|
|
|
#
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
select * from t1;
|
|
|
|
|
show create table t1;
|
|
|
|
|
drop table t1;
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# CAST to NCHAR with/without length
|
|
|
|
|
#
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
select * from t1;
|
|
|
|
|
show create table t1;
|
|
|
|
|
drop table t1;
|
|
|
|
|
|
|
|
|
|
|
2002-11-24 15:47:19 +02:00
|
|
|
|
#
|
|
|
|
|
# The following should be fixed in 4.1
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
select cast("2001-1-1" as date) = "2001-01-01";
|
|
|
|
|
select cast("2001-1-1" as datetime) = "2001-01-01 00:00:00";
|
|
|
|
|
select cast("1:2:3" as TIME) = "1:02:03";
|
2003-03-27 16:11:01 +02:00
|
|
|
|
select cast(NULL as DATE);
|
2003-03-28 16:57:03 +02:00
|
|
|
|
select cast(NULL as BINARY);
|