ERROR HY000: Illegal parameter data types uuid and int for operation 'coalesce'
SELECT LEAST(a, 10) FROM t1;
ERROR HY000: Illegal parameter data types uuid and int for operation 'least'
SELECT GREATEST(a, 10) FROM t1;
ERROR HY000: Illegal parameter data types uuid and int for operation 'greatest'
DROP TABLE t1;
SELECT COALESCE('garbage', CAST('::1' AS UUID));
COALESCE('garbage', CAST('::1' AS UUID))
NULL
Warnings:
Warning 1292 Incorrect uuid value: 'garbage'
Warning 1292 Incorrect uuid value: '::1'
SELECT COALESCE(0x01, CAST('::1' AS UUID));
COALESCE(0x01, CAST('::1' AS UUID))
NULL
Warnings:
Warning 1292 Incorrect uuid value: '\x01'
Warning 1292 Incorrect uuid value: '::1'
#
# Uniqueness
#
CREATE TABLE t1 (a UUID NOT NULL PRIMARY KEY);
INSERT INTO t1 VALUES
('41000000-0000-0000-0000-000000000001'),
('61000000-0000-0000-0000-000000000001');
INSERT INTO t1 VALUES ('41000000-0000-0000-0000-000000000001');
ERROR 23000: Duplicate entry '41000000-0000-0000-0000-000000000001' for key 'PRIMARY'
SELECT * FROM t1;
a
41000000-0000-0000-0000-000000000001
61000000-0000-0000-0000-000000000001
DROP TABLE t1;
#
# Indexes
#
CREATE TABLE t1 (a UUID, KEY(a(1)));
ERROR HY000: Incorrect prefix key; the used key part isn't a string, the used length is longer than the key part, or the storage engine doesn't support unique prefix keys
#
# Explicit CAST on INSERT
#
CREATE TABLE t1 (a UUID);
INSERT INTO t1 VALUES (CAST('10000000-0000-0000-0000-000000000001' AS UUID));
INSERT INTO t1 VALUES (CAST('10000000-0000-0000-0000-000000000002' AS UUID));
INSERT INTO t1 VALUES (CAST('10000000-0000-0000-0000-000000000003' AS UUID));
INSERT INTO t1 VALUES (CAST(CONCAT('2','0000000-0000-0000-0000-000000000001') AS UUID));
INSERT INTO t1 VALUES (CAST(CONCAT('2','0000000-0000-0000-0000-000000000002') AS UUID));
INSERT INTO t1 VALUES (CAST(CONCAT('2','0000000-0000-0000-0000-000000000003') AS UUID));
INSERT INTO t1 VALUES (CAST('00000000-0000-0000-0000-000000000000' AS UUID));
ERROR 01000: Data truncated for column 'a' at row 1
DROP TABLE t1;
CREATE TABLE t1 (a DOUBLE);
INSERT INTO t1 VALUES (CAST('00000000-0000-0000-0000-000000000000' AS UUID));
ERROR 01000: Data truncated for column 'a' at row 1
DROP TABLE t1;
CREATE TABLE t1 (a DECIMAL(32,0));
INSERT INTO t1 VALUES (CAST('00000000-0000-0000-0000-000000000000' AS UUID));
ERROR 01000: Data truncated for column 'a' at row 1
DROP TABLE t1;
CREATE TABLE t1 (a VARCHAR(64));
INSERT INTO t1 VALUES (CAST('00000000-0000-0000-0000-000000000000' AS UUID));
DROP TABLE t1;
CREATE TABLE t1 (a TEXT);
INSERT INTO t1 VALUES (CAST('00000000-0000-0000-0000-000000000000' AS UUID));
DROP TABLE t1;
#
# Boolean context
#
SELECT
CAST('00000000-0000-0000-0000-000000000000' AS UUID) IS TRUE,
CAST('00000000-0000-0000-0000-000000000000' AS UUID) IS FALSE,
CAST('00000000-0000-0000-0000-000000000001' AS UUID) IS TRUE,
CAST('00000000-0000-0000-0000-000000000001' AS UUID) IS FALSE;
CAST('00000000-0000-0000-0000-000000000000' AS UUID) IS TRUE CAST('00000000-0000-0000-0000-000000000000' AS UUID) IS FALSE CAST('00000000-0000-0000-0000-000000000001' AS UUID) IS TRUE CAST('00000000-0000-0000-0000-000000000001' AS UUID) IS FALSE
0 1 1 0
CREATE TABLE t1 (a UUID);
INSERT INTO t1 VALUES
('00000000-0000-0000-0000-000000000000'),
('00000000-0000-0000-0000-000000000001');
SELECT a, a IS TRUE, a IS FALSE FROM t1 ORDER BY a;
a a IS TRUE a IS FALSE
00000000-0000-0000-0000-000000000000 0 1
00000000-0000-0000-0000-000000000001 1 0
DROP TABLE t1;
CREATE TABLE t1 (a UUID);
INSERT INTO t1 VALUES
('00000000-0000-0000-0000-000000000000'),
('00000000-0000-0000-0000-000000000001'),
('00000000-0000-0000-0000-000000000002');
SELECT * FROM t1 WHERE a;
ERROR HY000: Illegal parameter data types uuid and bigint for operation '<>'
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=COALESCE(CAST('00000000-0000-0000-0000-000000000001' AS UUID)) AND id>0;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
Warnings:
Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` = UUID'00000000-0000-0000-0000-000000000001' and `test`.`t1`.`id` > 0
DROP TABLE t1;
#
# Optimizer: equal field propagation
#
CREATE TABLE t1 (id INT, a UUID);
INSERT INTO t1 VALUES
(1,'00000000-0000-0000-0000-000000000001'),
(2,'00000000-0000-0000-0000-000000000002');
EXPLAIN EXTENDED SELECT * FROM t1
WHERE a=COALESCE(CAST('00000000-0000-0000-0000-000000000001' AS UUID))
AND LENGTH(CONCAT(a,RAND()))>1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
Warnings:
Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` = UUID'00000000-0000-0000-0000-000000000001' and octet_length(concat(UUID'00000000-0000-0000-0000-000000000001',rand())) > 1
EXPLAIN EXTENDED SELECT * FROM t1
WHERE a=COALESCE(CAST('00000000-0000-0000-0000-000000000001' AS UUID))
AND LENGTH(a)>1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
Warnings:
Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` = UUID'00000000-0000-0000-0000-000000000001'
DROP TABLE t1;
#
# Optimizer: equal expression propagation
#
CREATE TABLE t1 (id INT, a UUID);
INSERT INTO t1 VALUES
(1,'00000000-0000-0000-0000-000000000001'),
(2,'00000000-0000-0000-0000-000000000002');
EXPLAIN EXTENDED SELECT * FROM t1
WHERE COALESCE(a)='00000000-0000-0000-0000-000000000001' AND COALESCE(a)=CONCAT(a);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
Warnings:
Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`a` AS `a` from `test`.`t1` where coalesce(`test`.`t1`.`a`) = '00000000-0000-0000-0000-000000000001' and concat(`test`.`t1`.`a`) = '00000000-0000-0000-0000-000000000001'
DROP TABLE t1;
#
# Subquery materialization
#
CREATE TABLE t1 (a UUID, b VARCHAR(36), KEY (a), KEY(b)) ;
INSERT INTO t1 VALUES
(
'00000000-0000-0000-0000-00000000000a',
'00000000-0000-0000-0000-00000000000a'
),
(
'00000000-0000-0000-0000-00000000000a',
'00000000-0000-0000-0000-00000000000b'
);
SET @@optimizer_switch='semijoin=off,materialization=on,in_to_exists=off,subquery_cache=off';
EXPLAIN SELECT * FROM t1 WHERE a IN (SELECT a AS a_inner FROM t1 GROUP BY a_inner);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where
2 MATERIALIZED t1 index NULL a 17 NULL 2 Using index
EXPLAIN SELECT * FROM t1 WHERE b IN (SELECT a AS a_inner FROM t1 GROUP BY a_inner);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where
2 DEPENDENT SUBQUERY t1 index_subquery a a 17 func 2 Using index; Using where
SET @@optimizer_switch=DEFAULT;
DROP TABLE t1;
#
# ALTER from UUID to UUID
#
CREATE TABLE t1 (a UUID, b INT);
INSERT INTO t1 VALUES ('00000000-0000-0000-0000-000000000001', 1);
ALTER TABLE t1 MODIFY b DECIMAL(10,2);
SELECT * FROM t1;
a b
00000000-0000-0000-0000-000000000001 1.00
DROP TABLE t1;
#
# ALTER to character string data types
#
CREATE OR REPLACE TABLE t1 (a UUID);
INSERT INTO t1 VALUES ('00000000-0000-0000-0000-000000000001');
SELECT CAST(a AS CHAR(36)) FROM t1;
CAST(a AS CHAR(36))
00000000-0000-0000-0000-000000000001
ALTER TABLE t1 MODIFY a CHAR(39);
SELECT * FROM t1;
a
00000000-0000-0000-0000-000000000001
DROP TABLE t1;
CREATE OR REPLACE TABLE t1 (a UUID);
INSERT INTO t1 VALUES ('00000000-0000-0000-0000-000000000001');
ALTER TABLE t1 MODIFY a VARCHAR(36);
SELECT * FROM t1;
a
00000000-0000-0000-0000-000000000001
DROP TABLE t1;
CREATE OR REPLACE TABLE t1 (a UUID);
INSERT INTO t1 VALUES ('00000000-0000-0000-0000-000000000001');
ALTER TABLE t1 MODIFY a TINYTEXT;
SELECT * FROM t1;
a
00000000-0000-0000-0000-000000000001
DROP TABLE t1;
CREATE OR REPLACE TABLE t1 (a UUID);
INSERT INTO t1 VALUES ('00000000-0000-0000-0000-000000000001');
ALTER TABLE t1 MODIFY a TEXT;
SELECT * FROM t1;
a
00000000-0000-0000-0000-000000000001
DROP TABLE t1;
CREATE OR REPLACE TABLE t1 (a UUID);
INSERT INTO t1 VALUES ('00000000-0000-0000-0000-000000000001');
ALTER TABLE t1 MODIFY a MEDIUMTEXT;
SELECT * FROM t1;
a
00000000-0000-0000-0000-000000000001
DROP TABLE t1;
CREATE OR REPLACE TABLE t1 (a UUID);
INSERT INTO t1 VALUES ('00000000-0000-0000-0000-000000000001');
ALTER TABLE t1 MODIFY a LONGTEXT;
SELECT * FROM t1;
a
00000000-0000-0000-0000-000000000001
DROP TABLE t1;
#
# ALTER from character string data types
#
CREATE OR REPLACE TABLE t1 (a CHAR(64));
INSERT INTO t1 VALUES ('00000000-0000-0000-0000-000000000001');
SELECT CAST(a AS UUID) FROM t1;
CAST(a AS UUID)
00000000-0000-0000-0000-000000000001
ALTER TABLE t1 MODIFY a UUID;
SELECT * FROM t1;
a
00000000-0000-0000-0000-000000000001
DROP TABLE t1;
CREATE OR REPLACE TABLE t1 (a VARCHAR(64));
INSERT INTO t1 VALUES ('00000000-0000-0000-0000-000000000001');
SELECT CAST(a AS UUID) FROM t1;
CAST(a AS UUID)
00000000-0000-0000-0000-000000000001
ALTER TABLE t1 MODIFY a UUID;
SELECT * FROM t1;
a
00000000-0000-0000-0000-000000000001
DROP TABLE t1;
CREATE OR REPLACE TABLE t1 (a TINYTEXT);
INSERT INTO t1 VALUES ('00000000-0000-0000-0000-000000000001');
SELECT CAST(a AS UUID) FROM t1;
CAST(a AS UUID)
00000000-0000-0000-0000-000000000001
ALTER TABLE t1 MODIFY a UUID;
SELECT * FROM t1;
a
00000000-0000-0000-0000-000000000001
DROP TABLE t1;
CREATE OR REPLACE TABLE t1 (a TEXT);
INSERT INTO t1 VALUES ('00000000-0000-0000-0000-000000000001');
SELECT CAST(a AS UUID) FROM t1;
CAST(a AS UUID)
00000000-0000-0000-0000-000000000001
ALTER TABLE t1 MODIFY a UUID;
SELECT * FROM t1;
a
00000000-0000-0000-0000-000000000001
DROP TABLE t1;
CREATE OR REPLACE TABLE t1 (a MEDIUMTEXT);
INSERT INTO t1 VALUES ('00000000-0000-0000-0000-000000000001');
SELECT CAST(a AS UUID) FROM t1;
CAST(a AS UUID)
00000000-0000-0000-0000-000000000001
ALTER TABLE t1 MODIFY a UUID;
SELECT * FROM t1;
a
00000000-0000-0000-0000-000000000001
DROP TABLE t1;
CREATE OR REPLACE TABLE t1 (a LONGTEXT);
INSERT INTO t1 VALUES ('00000000-0000-0000-0000-000000000001');
SELECT CAST(a AS UUID) FROM t1;
CAST(a AS UUID)
00000000-0000-0000-0000-000000000001
ALTER TABLE t1 MODIFY a UUID;
SELECT * FROM t1;
a
00000000-0000-0000-0000-000000000001
DROP TABLE t1;
#
# ALTER to binary string data types
#
CREATE TABLE t1 (a UUID);
INSERT INTO t1 VALUES ('00000000-0000-0000-0000-000000000001');
ALTER TABLE t1 MODIFY a BINARY(16);
SELECT HEX(a) FROM t1;
HEX(a)
00000000000000000000000000000001
DROP TABLE t1;
CREATE TABLE t1 (a UUID);
INSERT INTO t1 VALUES ('00000000-0000-0000-0000-000000000001');
ALTER TABLE t1 MODIFY a BINARY(17);
SELECT HEX(a) FROM t1;
HEX(a)
0000000000000000000000000000000100
DROP TABLE t1;
CREATE TABLE t1 (a UUID);
INSERT INTO t1 VALUES ('00000000-0000-0000-0000-000000000001');
ALTER TABLE t1 MODIFY a BINARY(15);
ERROR 22001: Data too long for column 'a' at row 1
DROP TABLE t1;
CREATE TABLE t1 (a UUID);
INSERT INTO t1 VALUES ('00000000-0000-0000-0000-000000000001');
ALTER TABLE t1 MODIFY a TINYBLOB;
SELECT HEX(a) FROM t1;
HEX(a)
00000000000000000000000000000001
DROP TABLE t1;
CREATE TABLE t1 (a UUID);
INSERT INTO t1 VALUES ('00000000-0000-0000-0000-000000000001');
ALTER TABLE t1 MODIFY a BLOB;
SELECT HEX(a) FROM t1;
HEX(a)
00000000000000000000000000000001
DROP TABLE t1;
CREATE TABLE t1 (a UUID);
INSERT INTO t1 VALUES ('00000000-0000-0000-0000-000000000001');
ALTER TABLE t1 MODIFY a MEDIUMBLOB;
SELECT HEX(a) FROM t1;
HEX(a)
00000000000000000000000000000001
DROP TABLE t1;
CREATE TABLE t1 (a UUID);
INSERT INTO t1 VALUES ('00000000-0000-0000-0000-000000000001');
ALTER TABLE t1 MODIFY a LONGBLOB;
SELECT HEX(a) FROM t1;
HEX(a)
00000000000000000000000000000001
DROP TABLE t1;
#
# ALTER from binary string data types
#
CREATE TABLE t1 (a BINARY(16));
INSERT INTO t1 VALUES (X'20010DB8000000000000FF0000428329');
ALTER TABLE t1 MODIFY a UUID;
SELECT a FROM t1;
a
20010db8-0000-0000-0000-ff0000428329
DROP TABLE t1;
CREATE TABLE t1 (a BINARY(17));
INSERT INTO t1 VALUES (X'20010DB8000000000000FF000042832900');
ALTER TABLE t1 MODIFY a UUID;
ERROR 22007: Incorrect uuid value: ' \x01\x0D\xB8\x00\x00\x00\x00\x00\x00\xFF\x00\x00B\x83)\x00' for column `test`.`t1`.`a` at row 1
DROP TABLE t1;
CREATE TABLE t1 (a BINARY(15));
INSERT INTO t1 VALUES (X'20010DB8000000000000FF00004283');
ALTER TABLE t1 MODIFY a UUID;
ERROR 22007: Incorrect uuid value: ' \x01\x0D\xB8\x00\x00\x00\x00\x00\x00\xFF\x00\x00B\x83' for column `test`.`t1`.`a` at row 1
DROP TABLE t1;
CREATE TABLE t1 (a TINYBLOB);
INSERT INTO t1 VALUES (X'20010DB8000000000000FF0000428329');
ALTER TABLE t1 MODIFY a UUID;
SELECT a FROM t1;
a
20010db8-0000-0000-0000-ff0000428329
DROP TABLE t1;
CREATE TABLE t1 (a BLOB);
INSERT INTO t1 VALUES (X'20010DB8000000000000FF0000428329');
ALTER TABLE t1 MODIFY a UUID;
SELECT a FROM t1;
a
20010db8-0000-0000-0000-ff0000428329
DROP TABLE t1;
CREATE TABLE t1 (a MEDIUMBLOB);
INSERT INTO t1 VALUES (X'20010DB8000000000000FF0000428329');
ALTER TABLE t1 MODIFY a UUID;
SELECT a FROM t1;
a
20010db8-0000-0000-0000-ff0000428329
DROP TABLE t1;
CREATE TABLE t1 (a BLOB);
INSERT INTO t1 VALUES (X'20010DB8000000000000FF0000428329');
ALTER TABLE t1 MODIFY a UUID;
SELECT a FROM t1;
a
20010db8-0000-0000-0000-ff0000428329
DROP TABLE t1;
#
# SET from UUID to UUID
#
CREATE TABLE t1 (a UUID, b UUID);
INSERT INTO t1 VALUES ('ffffffff-ffff-ffff-ffff-ffffffffffff', NULL);
UPDATE t1 SET b=a;
SELECT b FROM t1;
b
ffffffff-ffff-ffff-ffff-ffffffffffff
DROP TABLE t1;
#
# SET from UUID to numeric
#
CREATE TABLE t1 (a UUID, b INT);
INSERT INTO t1 VALUES ('ffffffff-ffff-ffff-ffff-ffffffffffff', NULL);
UPDATE t1 SET b=a;
ERROR 22007: Incorrect integer value: 'ffffffff-ffff-ffff-ffff-ffffffffffff' for column `test`.`t1`.`b` at row 1
SELECT b FROM t1;
b
NULL
DROP TABLE t1;
CREATE TABLE t1 (a UUID, b DOUBLE);
INSERT INTO t1 VALUES ('ffffffff-ffff-ffff-ffff-ffffffffffff', NULL);
UPDATE t1 SET b=a;
ERROR 22007: Incorrect double value: 'ffffffff-ffff-ffff-ffff-ffffffffffff' for column `test`.`t1`.`b` at row 1
SELECT b FROM t1;
b
NULL
DROP TABLE t1;
CREATE TABLE t1 (a UUID, b DECIMAL(32,0));
INSERT INTO t1 VALUES ('ffffffff-ffff-ffff-ffff-ffffffffffff', NULL);
UPDATE t1 SET b=a;
ERROR 22007: Incorrect decimal value: 'ffffffff-ffff-ffff-ffff-ffffffffffff' for column `test`.`t1`.`b` at row 1
SELECT b FROM t1;
b
NULL
DROP TABLE t1;
CREATE TABLE t1 (a UUID, b YEAR);
INSERT INTO t1 VALUES ('ffffffff-ffff-ffff-ffff-ffffffffffff', NULL);
UPDATE t1 SET b=a;
ERROR 22007: Incorrect integer value: 'ffffffff-ffff-ffff-ffff-ffffffffffff' for column `test`.`t1`.`b` at row 1
SELECT b FROM t1;
b
NULL
DROP TABLE t1;
#
# SET from numeric to UUID
#
CREATE TABLE t1 (a INT, b UUID);
INSERT INTO t1 VALUES (1, NULL);
UPDATE t1 SET b=a;
ERROR 22007: Incorrect uuid value: '1' for column `test`.`t1`.`b` at row 1
SELECT b FROM t1;
b
NULL
DROP TABLE t1;
CREATE TABLE t1 (a DOUBLE, b UUID);
INSERT INTO t1 VALUES (1, NULL);
UPDATE t1 SET b=a;
ERROR 22007: Incorrect uuid value: '1' for column `test`.`t1`.`b` at row 1
SELECT b FROM t1;
b
NULL
DROP TABLE t1;
CREATE TABLE t1 (a DECIMAL(32,0), b UUID);
INSERT INTO t1 VALUES (1, NULL);
UPDATE t1 SET b=a;
ERROR 22007: Incorrect uuid value: '1' for column `test`.`t1`.`b` at row 1
SELECT b FROM t1;
b
NULL
DROP TABLE t1;
CREATE TABLE t1 (a YEAR, b UUID);
INSERT INTO t1 VALUES (1, NULL);
UPDATE t1 SET b=a;
ERROR 22007: Incorrect uuid value: '2001' for column `test`.`t1`.`b` at row 1
SELECT b FROM t1;
b
NULL
DROP TABLE t1;
#
# SET from UUID to temporal
#
CREATE TABLE t1 (a UUID, b TIME);
INSERT INTO t1 VALUES ('ffffffff-ffff-ffff-ffff-ffffffffffff', NULL);
UPDATE t1 SET b=a;
ERROR 22007: Incorrect time value: 'ffffffff-ffff-ffff-ffff-ffffffffffff' for column `test`.`t1`.`b` at row 1
SELECT b FROM t1;
b
NULL
DROP TABLE t1;
CREATE TABLE t1 (a UUID, b DATE);
INSERT INTO t1 VALUES ('ffffffff-ffff-ffff-ffff-ffffffffffff', NULL);
UPDATE t1 SET b=a;
ERROR 22007: Incorrect date value: 'ffffffff-ffff-ffff-ffff-ffffffffffff' for column `test`.`t1`.`b` at row 1
SELECT b FROM t1;
b
NULL
DROP TABLE t1;
CREATE TABLE t1 (a UUID, b DATETIME);
INSERT INTO t1 VALUES ('ffffffff-ffff-ffff-ffff-ffffffffffff', NULL);
UPDATE t1 SET b=a;
ERROR 22007: Incorrect datetime value: 'ffffffff-ffff-ffff-ffff-ffffffffffff' for column `test`.`t1`.`b` at row 1
SELECT b FROM t1;
b
NULL
DROP TABLE t1;
CREATE TABLE t1 (a UUID, b TIMESTAMP NULL DEFAULT NULL);
INSERT INTO t1 VALUES ('ffffffff-ffff-ffff-ffff-ffffffffffff', NULL);
UPDATE t1 SET b=a;
ERROR 22007: Incorrect datetime value: 'ffffffff-ffff-ffff-ffff-ffffffffffff' for column `test`.`t1`.`b` at row 1
SELECT b FROM t1;
b
NULL
DROP TABLE t1;
#
# SET from temporal to UUID
#
CREATE TABLE t1 (a TIME, b UUID);
INSERT INTO t1 VALUES ('00:00:00', NULL);
UPDATE t1 SET b=a;
ERROR 22007: Incorrect uuid value: '00:00:00' for column `test`.`t1`.`b` at row 1
SELECT b FROM t1;
b
NULL
DROP TABLE t1;
CREATE TABLE t1 (a DATE, b UUID);
INSERT INTO t1 VALUES ('2001-01:01', NULL);
UPDATE t1 SET b=a;
ERROR 22007: Incorrect uuid value: '2001-01-01' for column `test`.`t1`.`b` at row 1
SELECT b FROM t1;
b
NULL
DROP TABLE t1;
CREATE TABLE t1 (a DATETIME, b UUID);
INSERT INTO t1 VALUES ('2001-01-01 10:20:30', NULL);
UPDATE t1 SET b=a;
ERROR 22007: Incorrect uuid value: '2001-01-01 10:20:30' for column `test`.`t1`.`b` at row 1
SELECT b FROM t1;
b
NULL
DROP TABLE t1;
CREATE TABLE t1 (a TIMESTAMP, b UUID);
INSERT INTO t1 VALUES ('2001-01-01 10:20:30', NULL);
UPDATE t1 SET b=a;
ERROR 22007: Incorrect uuid value: '2001-01-01 10:20:30' for column `test`.`t1`.`b` at row 1
SELECT b FROM t1;
b
NULL
DROP TABLE t1;
#
# SET from UUID to character string
#
CREATE TABLE t1 (a UUID, b CHAR(39));
INSERT INTO t1 VALUES ('ffffffff-ffff-ffff-ffff-ffffffffffff', NULL);
UPDATE t1 SET b=a;
SELECT b FROM t1;
b
ffffffff-ffff-ffff-ffff-ffffffffffff
DROP TABLE t1;
CREATE TABLE t1 (a UUID, b VARCHAR(39));
INSERT INTO t1 VALUES ('ffffffff-ffff-ffff-ffff-ffffffffffff', NULL);
UPDATE t1 SET b=a;
SELECT b FROM t1;
b
ffffffff-ffff-ffff-ffff-ffffffffffff
DROP TABLE t1;
CREATE TABLE t1 (a UUID, b TEXT);
INSERT INTO t1 VALUES ('ffffffff-ffff-ffff-ffff-ffffffffffff', NULL);
UPDATE t1 SET b=a;
SELECT b FROM t1;
b
ffffffff-ffff-ffff-ffff-ffffffffffff
DROP TABLE t1;
CREATE TABLE t1 (a UUID, b ENUM('ffffffff-ffff-ffff-ffff-ffffffffffff'));
INSERT INTO t1 VALUES ('ffffffff-ffff-ffff-ffff-ffffffffffff', NULL);
UPDATE t1 SET b=a;
SELECT b FROM t1;
b
ffffffff-ffff-ffff-ffff-ffffffffffff
DROP TABLE t1;
CREATE TABLE t1 (a UUID, b SET('ffffffff-ffff-ffff-ffff-ffffffffffff'));
INSERT INTO t1 VALUES ('ffffffff-ffff-ffff-ffff-ffffffffffff', NULL);
UPDATE t1 SET b=a;
SELECT b FROM t1;
b
ffffffff-ffff-ffff-ffff-ffffffffffff
DROP TABLE t1;
#
# SET from character string to UUID
#
CREATE TABLE t1 (a CHAR(36), b UUID);
INSERT INTO t1 VALUES ('ffffffff-ffff-ffff-ffff-ffffffffffff', NULL);
UPDATE t1 SET b=a;
SELECT b FROM t1;
b
ffffffff-ffff-ffff-ffff-ffffffffffff
DROP TABLE t1;
CREATE TABLE t1 (a VARCHAR(36), b UUID);
INSERT INTO t1 VALUES ('ffffffff-ffff-ffff-ffff-ffffffffffff', NULL);
UPDATE t1 SET b=a;
SELECT b FROM t1;
b
ffffffff-ffff-ffff-ffff-ffffffffffff
DROP TABLE t1;
CREATE TABLE t1 (a TEXT, b UUID);
INSERT INTO t1 VALUES ('ffffffff-ffff-ffff-ffff-ffffffffffff', NULL);
UPDATE t1 SET b=a;
SELECT b FROM t1;
b
ffffffff-ffff-ffff-ffff-ffffffffffff
DROP TABLE t1;
CREATE TABLE t1 (a ENUM('ffffffff-ffff-ffff-ffff-ffffffffffff'), b UUID);
INSERT INTO t1 VALUES ('ffffffff-ffff-ffff-ffff-ffffffffffff', NULL);
UPDATE t1 SET b=a;
SELECT b FROM t1;
b
ffffffff-ffff-ffff-ffff-ffffffffffff
DROP TABLE t1;
CREATE TABLE t1 (a SET('ffffffff-ffff-ffff-ffff-ffffffffffff'), b UUID);
INSERT INTO t1 VALUES ('ffffffff-ffff-ffff-ffff-ffffffffffff', NULL);
UPDATE t1 SET b=a;
SELECT b FROM t1;
b
ffffffff-ffff-ffff-ffff-ffffffffffff
DROP TABLE t1;
#
# SET from UUID to binary
#
CREATE TABLE t1 (a UUID, b BINARY(16));
INSERT INTO t1 VALUES ('ffffffff-ffff-ffff-ffff-ffffffffffff', NULL);
UPDATE t1 SET b=a;
SELECT HEX(b) FROM t1;
HEX(b)
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
DROP TABLE t1;
CREATE TABLE t1 (a UUID, b VARBINARY(39));
INSERT INTO t1 VALUES ('ffffffff-ffff-ffff-ffff-ffffffffffff', NULL);
UPDATE t1 SET b=a;
SELECT HEX(b) FROM t1;
HEX(b)
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
DROP TABLE t1;
CREATE TABLE t1 (a UUID, b BLOB);
INSERT INTO t1 VALUES ('ffffffff-ffff-ffff-ffff-ffffffffffff', NULL);
UPDATE t1 SET b=a;
SELECT HEX(b) FROM t1;
HEX(b)
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
DROP TABLE t1;
#
# SET from binary to UUID
#
CREATE TABLE t1 (a BINARY(16), b UUID);
INSERT INTO t1 VALUES (CONCAT(0xFFFF,REPEAT(0x0000,6),0xFFFF), NULL);
UPDATE t1 SET b=a;
SELECT b FROM t1;
b
ffff0000-0000-0000-0000-00000000ffff
DROP TABLE t1;
CREATE TABLE t1 (a VARBINARY(16), b UUID);
INSERT INTO t1 VALUES (CONCAT(0xFFFF,REPEAT(0x0000,6),0xFFFF), NULL);
UPDATE t1 SET b=a;
SELECT b FROM t1;
b
ffff0000-0000-0000-0000-00000000ffff
DROP TABLE t1;
CREATE TABLE t1 (a BLOB, b UUID);
INSERT INTO t1 VALUES (CONCAT(0xFFFF,REPEAT(0x0000,6),0xFFFF), NULL);
UPDATE t1 SET b=a;
SELECT b FROM t1;
b
ffff0000-0000-0000-0000-00000000ffff
DROP TABLE t1;
#
# Limit clause parameter
# TODO: this should fail.
# The test for a valid data type should be moved
# from parse time to fix_fields() time, and performed
# for both Item_splocal and Item_param.
#
EXECUTE IMMEDIATE 'SELECT 1 FROM DUAL LIMIT ?' USING CAST('00000000-0000-0000-0000-000000000000' AS UUID);
1
#
# ALTER from UUID to CHAR
#
CREATE OR REPLACE TABLE t1 (a UUID);
INSERT INTO t1 VALUES ('00000000-0000-0000-0000-000000000001');
SELECT CAST(a AS CHAR(36)) FROM t1;
CAST(a AS CHAR(36))
00000000-0000-0000-0000-000000000001
ALTER TABLE t1 MODIFY a CHAR(36);
SELECT * FROM t1;
a
00000000-0000-0000-0000-000000000001
DROP TABLE t1;
#
# ALTER from UUID to BINARY(16)
#
CREATE OR REPLACE TABLE t1 (a UUID);
INSERT INTO t1 VALUES ('00000000-0000-0000-0000-000000000001');
ALTER TABLE t1 MODIFY a BINARY(16);
SELECT HEX(a) FROM t1;
HEX(a)
00000000000000000000000000000001
DROP TABLE t1;
#
# CAST(uuid AS BINARY)
#
CREATE OR REPLACE TABLE t1 (a UUID);
INSERT INTO t1 VALUES ('00000000-0000-0000-0000-000000000001');
SELECT HEX(CAST(a AS BINARY)) FROM t1;
HEX(CAST(a AS BINARY))
00000000000000000000000000000001
SELECT HEX(CAST(a AS BINARY(16))) FROM t1;
HEX(CAST(a AS BINARY(16)))
00000000000000000000000000000001
DROP TABLE t1;
#
# CAST from UUID to FLOAT
#
CREATE TABLE t1 (a UUID);
INSERT INTO t1 VALUES ('00000000-0000-0000-0000-000000000000');
SELECT CAST(a AS FLOAT) FROM t1;
ERROR HY000: Illegal parameter data type uuid for operation 'float_typecast'
DROP TABLE t1;
#
# CAST(UUID AS BINARY) - metadata
#
CREATE TABLE t1 (a UUID);
SELECT
CAST(a AS BINARY(0)),
CAST(a AS BINARY(1)),
CAST(a AS BINARY(16)),
CAST(a AS BINARY(255)),
CAST(a AS BINARY(256)),
CAST(a AS BINARY(512)),
CAST(a AS BINARY(513)),
CAST(a AS BINARY(65532)),
CAST(a AS BINARY(65533)),
CAST(a AS BINARY(65534)),
CAST(a AS BINARY(65535)),
CAST(a AS BINARY(65536)),
CAST(a AS BINARY(16777215)),
CAST(a AS BINARY(16777216))
FROM t1;
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def CAST(a AS BINARY(0)) 254 0 0 Y 128 0 63
def CAST(a AS BINARY(1)) 254 1 0 Y 128 0 63
def CAST(a AS BINARY(16)) 254 16 0 Y 128 0 63
def CAST(a AS BINARY(255)) 254 255 0 Y 128 0 63
def CAST(a AS BINARY(256)) 253 256 0 Y 128 0 63
def CAST(a AS BINARY(512)) 253 512 0 Y 128 0 63
def CAST(a AS BINARY(513)) 253 513 0 Y 128 0 63
def CAST(a AS BINARY(65532)) 253 65532 0 Y 128 0 63
def CAST(a AS BINARY(65533)) 252 65533 0 Y 128 0 63
def CAST(a AS BINARY(65534)) 252 65534 0 Y 128 0 63
def CAST(a AS BINARY(65535)) 252 65535 0 Y 128 0 63
def CAST(a AS BINARY(65536)) 250 65536 0 Y 128 0 63
def CAST(a AS BINARY(16777215)) 250 16777215 0 Y 128 0 63
def CAST(a AS BINARY(16777216)) 251 16777216 0 Y 128 0 63
CAST(a AS BINARY(0)) CAST(a AS BINARY(1)) CAST(a AS BINARY(16)) CAST(a AS BINARY(255)) CAST(a AS BINARY(256)) CAST(a AS BINARY(512)) CAST(a AS BINARY(513)) CAST(a AS BINARY(65532)) CAST(a AS BINARY(65533)) CAST(a AS BINARY(65534)) CAST(a AS BINARY(65535)) CAST(a AS BINARY(65536)) CAST(a AS BINARY(16777215)) CAST(a AS BINARY(16777216))