github.com/matrixorigin/matrixone@v1.2.0/test/distributed/cases/function/func_cast.test (about) 1 select CAST(1-2 AS UNSIGNED); 2 select CAST(CAST(1-2 AS UNSIGNED) AS SIGNED INTEGER); 3 select CAST('10 ' as unsigned integer); 4 select CAST('10x' as unsigned integer); 5 6 select cast(-5 as unsigned) | 1, cast(-5 as unsigned) & -1; 7 8 select cast(-5 as unsigned) -1, cast(-5 as unsigned) + 1; 9 select cast(5 as unsigned) -6.0; 10 select cast(NULL as signed); 11 select cast(1/2 as signed); 12 #select cast("A" as binary) = "a", cast(BINARY "a" as CHAR) = "A"; 13 select cast("2001-1-1" as DATE), cast("2001-1-1" as DATETIME); 14 #select cast("1:2:3" as TIME); 15 #select CONVERT("2004-01-22 21:45:33",DATE); 16 select 10+'10'; 17 select 10.0+'10'; 18 select 10E+0+'10'; 19 # The following cast creates warnings 20 21 #SELECT CONVERT(TIMESTAMP "2004-01-22 21:45:33"); 22 #SELECT CONVERT(TIMESTAMP "2004-01-22 21:45:33", CHAR); 23 #SELECT CONVERT(TIMESTAMP "2004-01-22 21:45:33", CHAR(4)); 24 #SELECT CONVERT(TIMESTAMP "2004-01-22 21:45:33", BINARY(4)); 25 #select CAST(TIMESTAMP "2004-01-22 21:45:33" AS BINARY(4)); 26 select CAST(0xb3 as signed); 27 select CAST(0x8fffffffffffffff as signed); 28 select CAST(0xffffffffffffffff as unsigned); 29 select CAST(0xfffffffffffffffe as signed); 30 select cast('-10a' as signed integer); 31 select cast('a10' as unsigned integer); 32 select 10+'a'; 33 -- @bvt:issue#3280 34 select 10.0+cast('a' as decimal); 35 -- @bvt:issue 36 -- @bvt:issue#3276 37 select 10E+0+'a'; 38 -- @bvt:issue 39 40 # out-of-range cases 41 select cast('18446744073709551616' as unsigned); 42 select cast('18446744073709551616' as signed); 43 select cast('9223372036854775809' as signed); 44 select cast('-1' as unsigned); 45 select cast('abc' as signed); 46 select cast('1a' as signed); 47 select cast('' as signed); 48 # 49 # Character set conversion 50 # 51 #select hex(cast(_latin1'test' as char character set latin2)); 52 #select hex(cast(_koi8r x'D4C5D3D4' as char character set cp1251)); 53 #create table t1 select cast(_koi8r x'D4C5D3D4' as char character set cp1251) as t; 54 55 #Replace default engine value with static engine string 56 #show create table t1; 57 #drop table t1; 58 59 # 60 # CAST to CHAR with/without length 61 # 62 # select 63 # cast(_latin1'ab' AS char charset binary) as c1, 64 # cast(_latin1'a ' AS char charset binary) as c2, 65 # cast(_latin1'abc' AS char(2) charset binary) as c3, 66 # cast(_latin1'a ' AS char(2) charset binary) as c4, 67 # hex(cast(_latin1'a' AS char(2) charset binary)) as c5; 68 # select cast(1000 as CHAR(3) charset binary); 69 # SET sql_mode = 'NO_ENGINE_SUBSTITUTION'; 70 # create table t1 select 71 # cast(_latin1'ab' AS char charset binary) as c1, 72 # cast(_latin1'a ' AS char charset binary) as c2, 73 # cast(_latin1'abc' AS char(2) charset binary) as c3, 74 # cast(_latin1'a ' AS char(2) charset binary) as c4, 75 # cast(_latin1'a' AS char(2) charset binary) as c5; 76 # select c1,c2,c3,c4,hex(c5) from t1; 77 78 # #Replace default engine value with static engine string 79 # #replace_result $DEFAULT_ENGINE ENGINE 80 # show create table t1; 81 # drop table t1; 82 83 # 84 # CAST to NCHAR with/without length 85 # 86 87 # Different number of warnings with ps protocol. 88 # #disable_ps_protocol 89 # select 90 # cast(_koi8r x'C6C7' AS nchar) as c1, 91 # cast(_koi8r x'C620' AS nchar) as c2, 92 # cast(_koi8r x'C6C7C8' AS nchar(2)) as c3, 93 # cast(_koi8r x'C62020' AS nchar(2)) as c4, 94 # cast(_koi8r x'C6' AS nchar(2)) as c5; 95 # #enable_ps_protocol 96 97 # create table t1 select 98 # cast(_koi8r x'C6C7' AS nchar) as c1, 99 # cast(_koi8r x'C620' AS nchar) as c2, 100 # cast(_koi8r x'C6C7C8' AS nchar(2)) as c3, 101 # cast(_koi8r x'C62020' AS nchar(2)) as c4, 102 # cast(_koi8r x'C6' AS nchar(2)) as c5; 103 # select * from t1; 104 105 # #Replace default engine value with static engine string 106 # #replace_result $DEFAULT_ENGINE ENGINE 107 # show create table t1; 108 # drop table t1; 109 110 # #echo # 111 # #echo # Bug #24934161: FAILURE OF SYNONYMY OF NCHAR AND NATIONAL CHAR 112 # #echo # 113 114 # # Different number of warnings with ps protocol. 115 # #disable_ps_protocol 116 # SELECT 117 # CAST(_gb2312 x'CAFDBEDD' AS NATIONAL CHAR) AS c1, 118 # CAST(_gb2312 x'CAFD20' AS NATIONAL CHAR) AS c2, 119 # CAST(_gb2312 x'CAFDBEDDBFE2' AS NATIONAL CHAR(2)) AS c3, 120 # CAST(_gb2312 x'CAFD2020' AS NATIONAL CHAR(2)) AS c4, 121 # CAST(_gb2312 x'CAFD' AS NATIONAL CHAR(2)) AS c5; 122 # #enable_ps_protocol 123 124 # CREATE TABLE t1 SELECT 125 # CAST(_gb2312 x'CAFDBEDD' AS NATIONAL CHAR) AS c1, 126 # CAST(_gb2312 x'CAFD20' AS NATIONAL CHAR) AS c2, 127 # CAST(_gb2312 x'CAFDBEDDBFE2' AS NATIONAL CHAR(2)) AS c3, 128 # CAST(_gb2312 x'CAFD2020' AS NATIONAL CHAR(2)) AS c4, 129 # CAST(_gb2312 x'CAFD' AS NATIONAL CHAR(2)) AS c5; 130 # SELECT * FROM t1; 131 # SHOW CREATE TABLE t1; 132 # DROP TABLE t1; 133 134 # SET sql_mode = default; 135 # 136 # Bug 2202 137 # CAST from BINARY to non-BINARY and from non-BINARY to BINARY 138 # 139 # create table t1 (a binary(4), b char(4) character set koi8r); 140 # insert into t1 values (_binary x'D4C5D3D4',_binary x'D4C5D3D4'); 141 # select hex(a),hex(b),hex(cast(a as char character set cp1251)),hex(cast(b as binary)) from t1; 142 # drop table t1; 143 144 # 145 # The following should be fixed in 4.1 146 # 147 select cast("2001-1-1" as date) = "2001-01-01"; 148 select cast("2001-1-1" as datetime) = "2001-01-01 00:00:00"; 149 # select cast("1:2:3" as TIME) = "1:02:03"; 150 select cast(NULL as DATE); 151 # select cast(NULL as BINARY); 152 153 # 154 # Bug #5228 ORDER BY CAST(enumcol) sorts incorrectly under certain conditions 155 # 156 #CREATE TABLE t1 (a enum ('aac','aab','aaa') not null); 157 #INSERT INTO t1 VALUES ('aaa'),('aab'),('aac'); 158 # these two should be in enum order 159 # SELECT a, CAST(a AS CHAR) FROM t1 ORDER BY CAST(a AS UNSIGNED) ; 160 # SELECT a, CAST(a AS CHAR charset binary) FROM t1 ORDER BY CAST(a AS UNSIGNED) ; 161 # SELECT a, CAST(a AS CHAR(3) charset binary) FROM t1 ORDER BY CAST(a AS CHAR(2) charset binary), a; 162 # these two should be in alphabetic order 163 # SELECT a, CAST(a AS UNSIGNED) FROM t1 ORDER BY CAST(a AS CHAR) ; 164 # SELECT a, CAST(a AS UNSIGNED) FROM t1 ORDER BY CAST(a AS CHAR charset binary) ; 165 # SELECT a, CAST(a AS CHAR(2) charset binary ) FROM t1 ORDER BY CAST(a AS CHAR(3) charset binary), a; 166 #DROP TABLE t1; 167 168 # 169 # Test for bug #6914 "Problems using time()/date() output in expressions". 170 # When we are casting datetime value to DATE/TIME we should throw away 171 # time/date parts (correspondingly). 172 # 173 select date_add(cast('2004-12-30 12:00:00' as date), interval 0 hour); 174 # select timediff(cast('2004-12-30 12:00:00' as time), '12:00:00'); 175 # Still we should not throw away "days" part of time value 176 # select timediff(cast('1 12:00:00' as time), '12:00:00'); 177 178 # 179 # Bug #7036: Casting from string to unsigned would cap value of result at 180 # maximum signed value instead of maximum unsigned value 181 # 182 select cast(18446744073709551615 as unsigned); 183 select cast(18446744073709551615 as signed); 184 select cast('18446744073709551615' as unsigned); 185 select cast('18446744073709551615' as signed); 186 select cast('9223372036854775807' as signed); 187 188 select cast(concat_ws('184467440','73709551615') as unsigned); 189 select cast(concat_ws('184467440','73709551615') as signed); 190 191 #select cast(repeat('1',20) as unsigned); 192 #select cast(repeat('1',20) as signed); 193 194 # 195 # Bug #13344: cast of large decimal to signed int not handled correctly 196 # 197 select cast(1.0e+300 as signed int); 198 # 199 # Bugs: #15098: CAST(column double TO signed int), wrong result 200 # 201 CREATE TABLE t1 (f1 double); 202 INSERT INTO t1 SET f1 = -1.0e+30 ; 203 INSERT INTO t1 SET f1 = +1.0e+30 ; 204 SELECT f1 AS double_val, CAST(f1 AS SIGNED INT) AS cast_val FROM t1; 205 DROP TABLE t1; 206 207 -- @bvt:issue#3257 208 SELECT CAST(cast('01-01-01' as date) AS UNSIGNED); 209 SELECT CAST(cast('01-01-01' as date) AS SIGNED); 210 -- @bvt:issue 211 #echo End of 4.1 tests 212 213 214 #decimal-related additions 215 select cast('1.2' as decimal(3,2)); 216 select 1e18 * cast('1.2' as decimal(3,2)); 217 select cast(cast('1.2' as decimal(3,2)) as signed); 218 219 select cast(-1e18 as decimal(22,2)); 220 221 create table t1(s1 timestamp); 222 insert into t1 values ('2020-12-03 11:11:11'); 223 -- @bvt:issue#3257 224 select cast(s1 as decimal(7,2)) from t1; 225 -- @bvt:issue 226 drop table t1; 227 228 # 229 # Test for bug #11283: field conversion from varchar, and text types to decimal 230 # 231 232 CREATE TABLE t1 (v varchar(10), tt char(255), t char(255),mt char(255), lt char(255)); 233 INSERT INTO t1 VALUES ('1.01', '2.02', '3.03', '4.04', '5.05'); 234 SELECT CAST(v AS DECIMAL), CAST(tt AS DECIMAL), CAST(t AS DECIMAL), CAST(mt AS DECIMAL), CAST(lt AS DECIMAL) from t1; 235 DROP TABLE t1; 236 237 # 238 # Bug #10237 (CAST(NULL DECIMAL) crashes server) 239 # 240 select cast(NULL as decimal(6)) as t1; 241 242 243 # 244 # Bug #17903: cast to char results in binary 245 # 246 # set names latin1; 247 # select hex(cast('a' as char(2) binary)); 248 # select hex(cast('a' as binary(2))); 249 # select hex(cast('a' as char(2) binary)); 250 251 # 252 # Bug#29898: Item_date_typecast::val_int doesn't reset the null_value flag. 253 # 254 CREATE TABLE t1 (d1 datetime); 255 INSERT INTO t1(d1) VALUES ('2007-07-19 08:30:00'), (NULL), ('2007-07-19 08:34:00'), (NULL), ('2007-07-19 08:36:00'); 256 -- @bvt:issue#3293 257 SELECT cast(date(d1) as signed) FROM t1; 258 -- @bvt:issue 259 drop table t1; 260 261 # 262 # Bug #31990: MINUTE() and SECOND() return bogus results when used on a DATE 263 # 264 265 # Show that HH:MM:SS of a DATE are 0, and that it's the same for columns 266 # and typecasts (NULL in, NULL out). 267 #CREATE TABLE t1 (f1 DATE); 268 #INSERT INTO t1 VALUES ('2007-07-19'), (NULL); 269 #SELECT HOUR(f1),MINUTE(f1),SECOND(f1) FROM t1; 270 #SELECT HOUR(CAST('2007-07-19' AS DATE)),MINUTE(CAST('2007-07-19' AS DATE)),SECOND(CAST('2007-07-19' AS DATE)); 271 #SELECT HOUR(CAST(NULL AS DATE)),MINUTE(CAST(NULL AS DATE)),SECOND(CAST(NULL AS DATE)); 272 #SELECT HOUR(NULL),MINUTE(NULL),SECOND(NULL); 273 #DROP TABLE t1; 274 275 276 # #echo # 277 # #echo # Bug #44766: valgrind error when using convert() in a subquery 278 # #echo # 279 280 # CREATE TABLE t1(a tinyint); 281 # INSERT INTO t1 VALUES (127); 282 # SELECT 1 FROM 283 # ( 284 # SELECT CONVERT(t2.a USING UTF8) FROM t1, t1 t2 LIMIT 1 285 # ) AS s LIMIT 1; 286 # DROP TABLE t1; 287 288 # #echo # 289 # #echo # Bug #11765023: 57934: DOS POSSIBLE SINCE BINARY CASTING 290 # #echo # DOESN'T ADHERE TO MAX_ALLOWED_PACKET 291 292 # SET @@GLOBAL.max_allowed_packet=2048; 293 # # reconnect to make the new max packet size take effect 294 # #connect (newconn, localhost, root,,) 295 296 # SELECT CONVERT('a', BINARY(2049)); 297 # SELECT CONVERT('a', CHAR(2049)); 298 299 # connection default; 300 # disconnect newconn; 301 # SET @@GLOBAL.max_allowed_packet=default; 302 303 # #echo # 304 # #echo # Bug#13519724 63793: CRASH IN DTCOLLATION::SET(DTCOLLATION &SET) 305 # #echo # 306 307 # CREATE TABLE t1 (a VARCHAR(50)); 308 309 # SELECT a FROM t1 310 # WHERE CAST(a as BINARY)=x'62736D697468' 311 # AND CAST(a AS BINARY)=x'65736D697468'; 312 313 # DROP TABLE t1; 314 315 # #echo End of 5.1 tests 316 317 # #echo # 318 # #echo # Bug#22885819: CAST( .. AS BINARY(N)) GETS UNEXPECTED NULL 319 # #echo # 320 # SELECT CAST( 'a' AS BINARY(429496729)); 321 # SELECT CAST( 'a' AS BINARY(4294967294)); 322 # SELECT CAST( 'a' AS BINARY(4294967295)); 323 # #error ER_TOO_BIG_DISPLAYWIDTH 324 # SELECT CAST( 'a' AS BINARY(4294967296)); 325 # #error ER_TOO_BIG_DISPLAYWIDTH 326 # SELECT CAST( 'a' AS BINARY(4294967296784564)); 327 328 # #echo # 329 # #echo # Bug#13581962 HIGH MEMORY USAGE ATTEMPT, THEN CRASH WITH LONGTEXT, UNION, USER VARIABLE 330 # #echo # 331 # SET sql_mode = 'NO_ENGINE_SUBSTITUTION'; 332 # CREATE TABLE t1 AS SELECT CONCAT(CAST(REPEAT('9', 1000) AS SIGNED)), 333 # CONCAT(CAST(REPEAT('9', 1000) AS UNSIGNED)); 334 335 # #Replace default engine value with static engine string 336 # #replace_result $DEFAULT_ENGINE ENGINE 337 # SHOW CREATE TABLE t1; 338 # DROP TABLE t1; 339 # SET sql_mode = default; 340 # #echo End of 5.5 tests 341 342 # #echo # 343 # #echo # Bug#28547906 ENUM TYPE CASTING WORKS WRONG WITH SUBQUERIES 344 # #echo # 345 #CREATE TABLE t (c1 ENUM('a','b','c')); 346 #INSERT INTO t VALUES ('a'), ('b'), ('c'); 347 #SELECT CAST(c1 AS UNSIGNED) AS c5 FROM t; 348 #SELECT CAST(c1 AS UNSIGNED) AS c5 FROM (SELECT c1 FROM t) t; 349 #DROP TABLE t; 350 351 # #echo # 352 # #echo # CAST as DOUBLE/FLOAT/REAL 353 # #echo # 354 SELECT CAST(1/3 AS FLOAT) as float_col,CAST(1/3 AS DOUBLE) as double_col, CAST(1/3 AS REAL) as real_col; 355 356 357 # SELECT CAST(1/3 AS FLOAT(10)), CAST(1/3 AS FLOAT(53)); 358 # #error ER_PARSE_ERROR 359 # SELECT CAST(1/3 AS FLOAT(-1)); 360 # #error ER_TOO_BIG_PRECISION 361 # SELECT CAST(1/3 AS FLOAT(54)); 362 # #error ER_PARSE_ERROR 363 # SELECT CAST(1/3 AS DOUBLE(52)); 364 # #error ER_PARSE_ERROR 365 # SELECT CAST(1/3 AS REAL(34)); 366 367 # #error ER_PARSE_ERROR 368 # SELECT CAST(999.00009 AS FLOAT(7,4)) as float_col; 369 # #error ER_PARSE_ERROR 370 # SELECT CAST(999.00009 AS DOUBLE(7,4)) as double_col; 371 # #error ER_PARSE_ERROR 372 # SELECT CAST(999.00009 AS REAL(7,4)) as real_col; 373 374 #SELECT ADDDATE(CAST("20010101235959.9" AS DOUBLE), INTERVAL 1 DAY); 375 #SELECT TIMEDIFF(CAST("101112" AS DOUBLE), TIME'101010'); 376 SELECT CAST(DATE'2000-01-01' AS FLOAT), CAST(DATE'2000-01-01' AS DOUBLE); 377 #SELECT CAST(TIME'23:59:59' AS FLOAT), CAST(TIME'23:59:59' AS DOUBLE); 378 #SELECT CAST(TIME'23:59:59.123456' AS FLOAT), 379 # CAST(TIME'23:59:59.123456' AS DOUBLE); 380 SELECT CAST(TIMESTAMP'2000-01-01 23:59:59' AS FLOAT), CAST(TIMESTAMP'2000-01-01 23:59:59' AS DOUBLE); 381 SELECT CAST(TIMESTAMP'2000-01-01 23:59:59.123456' AS FLOAT), CAST(TIMESTAMP'2000-01-01 23:59:59.123456' AS DOUBLE); 382 383 384 #CREATE TABLE t1 as SELECT CAST(1/3 AS FLOAT) as float_col, 385 # CAST(1/3 AS DOUBLE) as double_col, 386 # CAST(CAST(999.00009 AS DECIMAL(7,4)) AS DOUBLE) as d2; 387 #SHOW CREATE TABLE t1; 388 #DROP TABLE t1; 389 390 # Function that forces Item_typecast_real::val_int() to be called to generate overflow 391 #error ER_DATA_OUT_OF_RANGE 392 #SELECT PERIOD_ADD(200905, CAST(3.14e19 AS DOUBLE)); 393 #SELECT -1.0 * CAST(3.14e19 AS DOUBLE); 394 #error ER_DATA_OUT_OF_RANGE 395 #SELECT CAST("3.14e100" AS FLOAT); 396 #error ER_DATA_OUT_OF_RANGE 397 #SELECT CAST(-1e308 as FLOAT); 398 #SELECT CONCAT("value=", CAST("3.4e5" AS FLOAT)); 399 400 # CREATE VIEW v1 AS SELECT CAST(1/3 AS REAL), CAST(1/3 AS FLOAT(2)), CAST(1/3 AS FLOAT(50)); 401 # SHOW CREATE VIEW v1; 402 # DROP VIEW v1; 403 404 405 SELECT CAST(NULL AS REAL), CAST(NULL AS FLOAT), CAST(NULL AS DOUBLE); 406 407 # SET @OLD_SQL_MODE=@@SQL_MODE, @@SQL_MODE=REAL_AS_FLOAT; 408 # CREATE TABLE t AS SELECT CAST(34 AS REAL); 409 # SHOW CREATE TABLE t; 410 # DROP TABLE t; 411 # SET @@SQL_MODE=@OLD_SQL_MODE; 412 # CREATE TABLE t AS SELECT CAST(34 AS REAL); 413 # SHOW CREATE TABLE t; 414 # DROP TABLE t; 415 416 # SELECT MAKETIME(1, 2, CAST("1.6" AS FLOAT)); 417 418 419 420 # #echo # 421 # #echo # Bug#31023252: RESULTSET MISMATCH USING STRCMP() WITH DATE AND STRING DATATYPE 422 # #echo # 423 # CREATE TABLE t1(a YEAR, b VARCHAR(10)); 424 # INSERT INTO t1 VALUES ('1997','random_str'); 425 # SELECT STRCMP(a, b) FROM t1; 426 # DROP TABLE t1; 427 428 #echo # 429 #echo # Bug#30626100: WL13456 RESULTSET DISTINCT DIFFERENCE 430 #echo # 431 CREATE TABLE t (col_datetime datetime, col_date date, col_char char); 432 insert into t values ('2013-03-15 18:35:20', '2013-03-15','L'),('2003-01-10 00:00:23', '2003-01-10', NULL); 433 434 435 #skip_if_hypergraph # Different warnings. 436 437 SELECT CAST(col_char AS DATETIME) FROM t; 438 #echo 439 #skip_if_hypergraph # Different warnings. 440 SELECT col_char <> col_datetime FROM t; 441 442 #echo 443 #skip_if_hypergraph # Different warnings. 444 SELECT CAST(col_char AS DATE) FROM t; 445 446 447 #echo 448 #skip_if_hypergraph # Different warnings. 449 -- @bvt:issue#3253 450 SELECT col_char <> col_date FROM t; 451 -- @bvt:issue 452 #SELECT CAST(col_char as TIME) FROM t; 453 454 DROP TABLE t; 455 456 #echo # 457 #echo # Bug#31095719 WL13456 RESULT SET COMPARISON DIFFERENCE WITH JOINS 458 #echo # 459 CREATE TABLE `BB` (`col_char_key` char(1)); 460 CREATE TABLE `CC` ( `pk` int, `col_datetime_key` datetime); 461 INSERT INTO `BB` VALUES ('X'); 462 INSERT INTO `CC` VALUES (1,'2027-03-17 00:10:00'), (2,'2004-11-14 12:46:43'); 463 #skip_if_hypergraph # Different warnings. 464 -- @bvt:issue#3254 465 SELECT COUNT(table1.pk) FROM `CC` table1 JOIN `BB` table3 JOIN `CC` table2 466 WHERE (table3.col_char_key < table2.col_datetime_key); 467 -- @bvt:issue 468 DROP TABLE `BB`; 469 DROP TABLE `CC`; 470 471 #echo # 472 #echo # CAST AS YEAR 473 #echo # 474 475 # # int values 476 # SELECT CAST(CAST(-1 AS SIGNED) AS YEAR); 477 # SELECT CAST(CAST(-99 AS SIGNED) AS YEAR); 478 # SELECT CAST(CAST(0 AS SIGNED) AS YEAR); 479 # SELECT CAST(CAST(69 AS SIGNED) AS YEAR); 480 # SELECT CAST(CAST(70 AS SIGNED) AS YEAR); 481 # SELECT CAST(CAST(99 AS SIGNED) AS YEAR); 482 # SELECT CAST(CAST(100 AS SIGNED) AS YEAR); 483 # SELECT CAST(CAST(2010 AS SIGNED) AS YEAR); 484 485 # #floating point values 486 # SELECT CAST(-1.1 AS YEAR); 487 # SELECT CAST(1.1 AS YEAR); 488 # SELECT CAST(0.0 AS YEAR); 489 # SELECT CAST(69.1 AS YEAR); 490 # SELECT CAST(70.1 AS YEAR); 491 # SELECT CAST(100.1 AS YEAR); 492 # SELECT CAST(2010.9 AS YEAR); 493 494 # #decimal values 495 # SELECT CAST(CAST(-1.1 AS DECIMAL) AS YEAR); 496 # SELECT CAST(CAST(1.1 AS DECIMAL) AS YEAR); 497 # SELECT CAST(CAST(0.0 AS DECIMAL) AS YEAR); 498 # SELECT CAST(CAST(69.1 AS DECIMAL) AS YEAR); 499 # SELECT CAST(CAST(70.1 AS DECIMAL) AS YEAR); 500 # SELECT CAST(CAST(100.1 AS DECIMAL) AS YEAR); 501 # SELECT CAST(CAST(2010.9 AS DECIMAL) AS YEAR); 502 503 # #string values 504 # SELECT CAST("-1" AS YEAR); 505 # SELECT CAST("-99" AS YEAR); 506 # SELECT CAST("0" AS YEAR); 507 # SELECT CAST("69" AS YEAR); 508 # SELECT CAST("70" AS YEAR); 509 # SELECT CAST("99" AS YEAR); 510 # SELECT CAST("100" AS YEAR); 511 # SELECT CAST("2010" AS YEAR); 512 # SELECT CAST("extra" AS YEAR); 513 # SELECT CAST("22extra" AS YEAR); 514 # SELECT CAST("2020extra" AS YEAR); 515 516 # SET timestamp = UNIX_TIMESTAMP('2020-12-22 03:30:00'); 517 # #date[time] values 518 # SELECT CAST(TIMESTAMP'2010-01-01 00:00' AS YEAR); 519 # SET SQL_MODE = ""; 520 # SELECT CAST(TIMESTAMP'0000-00-00 00:00' AS YEAR); 521 # SET SQL_MODE = default; 522 # SELECT CAST(TIMESTAMP'2010-01-01 08:09:10' AS YEAR); 523 # SELECT CAST(TIME'08:09:10' AS YEAR); 524 # SELECT CAST(TIME'00:00:00' AS YEAR); 525 # SET timestamp = DEFAULT; 526 527 # #geometry values 528 # #error ER_WRONG_ARGUMENTS 529 # SELECT CAST(ST_PointFromText('POINT(10 10)') AS YEAR); 530 531 # #CREATE AS SELECT 532 # CREATE TABLE t AS SELECT CAST("2010" AS YEAR); 533 # SHOW CREATE TABLE t; 534 # DROP TABLE t; 535 536 # #json values 537 # SELECT CAST(JSON_EXTRACT('{"key_year":1934}', '$.key_year') AS YEAR); 538 # SELECT CAST(CAST('{"_id":"192312412512"}' AS JSON) AS YEAR); 539 540 # CREATE TABLE t1 (i INT, j JSON) CHARSET utf8mb4; 541 # INSERT INTO t1 VALUES (0, NULL); 542 # INSERT INTO t1 VALUES (1, '"1901"'); 543 # INSERT INTO t1 VALUES (2, 'true'); 544 # INSERT INTO t1 VALUES (3, 'false'); 545 # INSERT INTO t1 VALUES (4, 'null'); 546 # INSERT INTO t1 VALUES (5, '-1'); 547 # INSERT INTO t1 VALUES (6, CAST(CAST(1 AS UNSIGNED) AS JSON)); 548 # INSERT INTO t1 VALUES (7, '1901'); 549 # INSERT INTO t1 VALUES (8, '-1901'); 550 # INSERT INTO t1 VALUES (9, '2147483647'); 551 # INSERT INTO t1 VALUES (10, '2147483648'); 552 # INSERT INTO t1 VALUES (11, '-2147483648'); 553 # INSERT INTO t1 VALUES (12, '-2147483649'); 554 # INSERT INTO t1 VALUES (13, '3.14'); 555 # INSERT INTO t1 VALUES (14, '{}'); 556 # INSERT INTO t1 VALUES (15, '[]'); 557 # INSERT INTO t1 VALUES (16, CAST(CAST('2015-01-15 23:24:25' AS DATETIME) AS JSON)); 558 # INSERT INTO t1 VALUES (17, CAST(CAST('23:24:25' AS TIME) AS JSON)); 559 # INSERT INTO t1 VALUES (18, CAST(CAST('2015-01-15' AS DATE) AS JSON)); 560 # INSERT INTO t1 VALUES (19, CAST(TIMESTAMP'2015-01-15 23:24:25' AS JSON)); 561 # INSERT INTO t1 VALUES (20, CAST(ST_GeomFromText('POINT(1 1)') AS JSON)); 562 # INSERT INTO t1 VALUES (21, CAST('1988' AS CHAR CHARACTER SET 'ascii')); 563 # INSERT INTO t1 VALUES (22, CAST(x'07C4' AS JSON)); 564 # INSERT INTO t1 VALUES (23, CAST(x'07C407C4' AS JSON)); 565 # SELECT i, CAST(j AS YEAR), CAST(j AS SIGNED) FROM t1 ORDER BY i; 566 # DROP TABLE t1; 567 568 # # enum values 569 # CREATE TABLE t(numbers ENUM('0','1','2020'), colors ENUM('red', 'green', 'blue')); 570 # INSERT INTO t values('2020', 'blue'); 571 # SELECT CAST(numbers AS YEAR), CAST(colors AS YEAR) FROM t; 572 # DROP TABLE t; 573 574 # # with/without strict mode 575 # CREATE TABLE t(y YEAR); 576 # #error ER_TRUNCATED_WRONG_VALUE 577 # INSERT INTO t values(CAST("2020extra" AS YEAR)); 578 # #error ER_TRUNCATED_WRONG_VALUE 579 # INSERT INTO t values(CAST(20201 AS YEAR)); 580 581 # SET SQL_MODE = ""; 582 # INSERT INTO t values(CAST("2020extra" AS YEAR)); 583 # INSERT INTO t values(CAST(20201 AS YEAR)); 584 # SELECT * FROM t; 585 # SET SQL_MODE = default; 586 # DROP TABLE t; 587 588 # SELECT CAST(1988 AS YEAR), REPEAT(CAST(1988 AS YEAR), 3) AS c2; 589 # SELECT CONCAT_WS('x', CAST(1988 AS YEAR)); 590 # SELECT CAST(1988 AS YEAR) + 1.5e0; 591 # SELECT CAST(CAST(1988 AS YEAR) AS DECIMAL); 592 # SELECT DATE_ADD(CAST(1988 AS YEAR), INTERVAL 1 DAY); 593 # SELECT CAST(CAST(1988 AS YEAR) AS SIGNED); 594 # SELECT CAST(CAST(1988 AS YEAR) AS UNSIGNED); 595 # SELECT CAST(TIMESTAMP'579-10-10 10:10:10' AS YEAR); 596 597 #echo # WL#14109: Implement a consistent comparison type rule matrix 598 599 # Check CAST into temporal values and mode settings 600 601 create table t1(f1 date, f2 timestamp, f3 datetime); 602 insert into t1 values ("2006-01-01", "2006-01-01 12:01:01", "2006-01-01 12:01:01"); 603 insert into t1 values ("2006-01-02", "2006-01-02 12:01:02", "2006-01-02 12:01:02"); 604 605 select f1 from t1 where f1 between CAST("2006-1-1" as date) and CAST(20060101 as date); 606 select f1 from t1 where f1 between cast("2006-1-1" as date) and cast("2006.1.1" as date); 607 select f1 from t1 where date(f1) between cast("2006-1-1" as date) and cast("2006.1.1" as date); 608 select f3 from t1 where f3 between cast("2006-1-1 12:1:1" as datetime) and cast("2006-1-1 12:1:2" as datetime); 609 select f3 from t1 where timestamp(f3) between cast("2006-1-1 12:1:1" as datetime) and cast("2006-1-1 12:1:2" as datetime); 610 select f1 from t1 where cast("2006-1-1" as date) between f1 and f3; 611 select f1 from t1 where cast("2006-1-1" as date) between date(f1) and date(f3); 612 select f1 from t1 where cast("2006-1-1" as date) between f1 and cast('zzz' as date); 613 614 drop table t1; 615 616 617 618 create table t1 (field DATE); 619 insert into t1 values ('2006-11-06'); 620 -- @bvt:issue#3253 621 select * from t1 where field < '2006-11-06 04:08:36.0'; 622 select * from t1 where field = '2006-11-06 04:08:36.0'; 623 select * from t1 where field = '2006-11-06'; 624 -- @bvt:issue 625 -- @bvt:issue#3254 626 select * from t1 where CAST(field as DATETIME) < '2006-11-06 04:08:36.0'; 627 -- @bvt:issue 628 -- @bvt:issue#3253 629 select * from t1 where CAST(field as DATE) < '2006-11-06 04:08:36.0'; 630 -- @bvt:issue 631 drop table t1; 632 633 create table t1 (a int(11) unsigned, b int(11) unsigned); 634 insert into t1 values (1,0), (1,1), (4294967295,1); 635 select a-b from t1 order by 1; 636 select a-b , (a-b < 0) from t1 order by 1; 637 select any_value(a)-b as d, (any_value(a)-b >= 0), b from t1 group by b having d >= 0; 638 select cast((a - b) as unsigned) from t1 order by 1; 639 drop table t1; 640 641 642 #SELECT CAST(IFNULL(NULL, NULL) AS DECIMAL); 643 select if(1, cast(1111111111111111111 as unsigned), 1) i, case when 1 then cast(1111111111111111111 as unsigned) else 1 end c, coalesce(cast(1111111111111111111 as unsigned), 1) co; 644 645 #CREATE TABLE t1 (f1 int, 646 #gc_int int AS (f1 + 1) , 647 #gc_date DATE AS (f1 + 1)); 648 #INSERT INTO t1(f1) VALUES 649 #(030303),(040404), 650 #(050505),(060606), 651 #(010101),(020202), 652 #(030303),(040404), 653 #(050505),(060606), 654 #(010101),(020202), 655 #(090909),(101010), 656 #(010101),(020202), 657 #(070707),(080808); 658 #SELECT * FROM t1 WHERE f1 + 1 > 070707; 659 #SELECT * FROM t1 WHERE f1 + 1 > CAST(070707 AS DATE); 660 #DROP TABLE t1; 661 662 create database if not exists test; 663 use test; 664 drop table if exists `alarm`; 665 CREATE TABLE `alarm` ( 666 `alarm_id` INT NOT NULL AUTO_INCREMENT, 667 `var_name` TEXT DEFAULT NULL, 668 `address` TEXT DEFAULT NULL, 669 `var_type` TEXT DEFAULT NULL, 670 `alarm_value` TEXT DEFAULT NULL, 671 `current_value` TEXT DEFAULT NULL, 672 `priority` INT DEFAULT null, 673 `operator` TEXT DEFAULT NULL, 674 `insert_time` BLOB DEFAULT NULL, 675 `note` TEXT DEFAULT NULL, 676 PRIMARY KEY (`alarm_id`) 677 ); 678 679 INSERT INTO `alarm` VALUES (2,'测试','M100.0','Bool','True','True',0,'管理员',_binary '2023-03-01 14:20:29','报警测试'),(3,'测试','M100.0','Bool','True','True',0,'管理员',_binary '2023-03-01 14:20:41','报警测试'),(4,'测试','M100.0','Bool','True','True',0,'管理员',_binary '2023-03-01 14:20:46','报警测试'),(5,'Emergency','M1000.4','bool','False','False',1,'Admin',_binary '2023-03-03 14:29:26.327337','设备急停中'),(6,'Emergency','M1000.4','bool','False','False',1,'Admin',_binary '2023-03-05 11:38:10.6059081','设备急停中'),(7,'Emergency','M1000.4','bool','False','False',1,'Admin',_binary '2023-03-15 07:55:37.1308852','设备急停中'),(8,'Emergency','M1000.4','bool','False','False',1,'Admin',_binary '2023-03-15 08:02:48.7571227','设备急停中'),(9,'Emergency','M1000.4','bool','False','False',1,'Admin',_binary '2023-03-19 03:27:49.5087995','设备急停中'),(10,'Emergency','M1000.4','bool','False','False',1,'Admin',_binary '2023-03-22 00:05:23.1781761','设备急停中'),(11,'Emergency','M1000.4','bool','False','False',1,'Admin',_binary '2023-03-22 16:05:08.6198487','设备急停中'),(12,'Emergency','M1000.4','bool','False','False',1,'Admin',_binary '2023-03-22 16:12:10.8425965','设备急停中'),(13,'Emergency','M1000.4','bool','False','False',1,'Admin',_binary '2023-03-22 16:24:30.269232','设备急停中'),(14,'Emergency','M1000.4','bool','False','False',1,'Admin',_binary '2023-03-22 16:25:16.3121285','设备急停中'),(15,'Emergency','M1000.4','bool','False','False',1,'Admin',_binary '2023-03-22 16:25:23.5447725','设备急停中'),(16,'Emergency','M1000.4','bool','False','False',1,'Admin',_binary '2023-03-22 20:34:57.8534506','设备急停中'),(17,'Emergency','M1000.4','bool','False','False',1,'Admin',_binary '2023-03-22 20:35:20.1639042','设备急停中'),(18,'Emergency','M1000.4','bool','False','False',1,'Admin',_binary '2023-03-22 20:45:27.0464144','设备急停中'),(19,'Emergency','M1000.4','bool','False','False',1,'Admin',_binary '2023-03-22 20:49:59.5979518','设备急停中'),(20,'Emergency','M1000.4','bool','False','False',1,'Admin',_binary '2023-03-23 01:26:46.1155487','设备急停中'),(21,'Emergency','M1000.4','bool','False','False',1,'Admin',_binary '2023-03-30 06:33:50.6666203','设备急停中'),(22,'Emergency','M1000.4','bool','False','False',1,'Admin',_binary '2023-04-03 05:44:03.5318075','设备急停中'),(23,'Emergency','M1000.4','bool','False','False',1,'Admin',_binary '2023-04-03 05:45:01.64952','设备急停中'),(24,'Emergency','M1000.4','bool','False','False',1,'Admin',_binary '2023-04-03 05:46:37.8612795','设备急停中'),(25,'Emergency','M1000.4','bool','False','False',1,'Admin',_binary '2023-04-03 06:05:06.5081611','设备急停中'),(26,'Emergency','M1000.4','bool','False','False',1,'Admin',_binary '2023-04-03 12:21:23.1368163','设备急停中'),(27,'Emergency','M1000.4','bool','False','False',1,'Admin',_binary '2023-04-03 12:25:45.5234186','设备急停中'),(28,'Emergency','M1000.4','bool','False','False',1,'Admin',_binary '2023-04-03 18:22:29.7438075','设备急停中'),(29,'Emergency','M1000.4','bool','False','False',1,'Admin',_binary '2023-04-04 06:52:07.473582','设备急停中'),(30,'Emergency','M1000.4','bool','False','False',1,'Admin',_binary '2023-04-04 08:32:50.2166836','设备急停中'),(31,'测试报警','M100','bool','true','true',1,'Admin',_binary '2023-04-06 21:00:09.7964362','note测试报警'); 680 SELECT * FROM `alarm`; 681 drop database test;