|
SET sql_mode=STRICT_ALL_TABLES;
|
DROP TABLE IF EXISTS t1, t2;
|
CREATE TABLE t1 (a TINYINT);
|
INSERT INTO t1 VALUES (-1);
|
CREATE TABLE t2 AS SELECT a, HEX(a) AS h FROM t1;
|
ERROR 1406 (22001): Data too long for column 'h' at row 1
|
Looks wrong.
This script:
CREATE TABLE t2 AS SELECT a, HEX(a) AS h FROM t1 LIMIT 0;
|
SHOW CREATE TABLE t2;
|
demonstrates that the data type for the column h is too short:
+-------+--------------------------------------------------------------------------------------------------------------------------------------------+
|
| Table | Create Table |
|
+-------+--------------------------------------------------------------------------------------------------------------------------------------------+
|
| t2 | CREATE TABLE `t2` (
|
`a` tinyint(4) DEFAULT NULL,
|
`h` varchar(8) CHARACTER SET utf8 DEFAULT NULL
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
|
+-------+--------------------------------------------------------------------------------------------------------------------------------------------+
|
It should be varchar(16) to fit hex representation of positive completents for negative numbers:
SELECT a, HEX(a) FROM t1;
|
+------+------------------+
|
| a | HEX(a) |
|
+------+------------------+
|
| -1 | FFFFFFFFFFFFFFFF |
|
+------+------------------+
|
|