Description:
create table .. as select ... quote() gives wrong varchar length for all
character sets.
For 5.7 and older, quote('a') will give varchar(4), not varchar(3) as expected.
For 8.0 the length of the column varies with the charset variables:
mysql> set names latin1;
Query OK, 0 rows affected (0.00 sec)
mysql> create table t1 as select quote('a');
Query OK, 1 row affected (0.02 sec)
Records: 1 Duplicates: 0 Warnings: 0
mysql> show create table t1;
+-------+-------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+-------------------------------------------------------------------------------------------------------------------------+
| t1 | CREATE TABLE `t1` (
`quote('a')` varchar(4) CHARACTER SET latin1 DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 |
+-------+-------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> set names utf8;
Query OK, 0 rows affected (0.00 sec)
mysql> create table t2 as select quote('a');
Query OK, 1 row affected (0.02 sec)
Records: 1 Duplicates: 0 Warnings: 0
mysql> show create table t2;
+-------+-----------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+-----------------------------------------------------------------------------------------------------------------------+
| t2 | CREATE TABLE `t2` (
`quote('a')` varchar(8) CHARACTER SET utf8 DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 |
+-------+-----------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> set names utf8mb4;
Query OK, 0 rows affected (0.00 sec)
mysql> create table t3 as select quote('a');
Query OK, 1 row affected (0.01 sec)
Records: 1 Duplicates: 0 Warnings: 0
mysql> show create table t3;
+-------+-----------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+-----------------------------------------------------------------------------------------------------+
| t3 | CREATE TABLE `t3` (
`quote('a')` varchar(10) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 |
+-------+-----------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql>
How to repeat:
set names latin1;
create table t1 as select quote('a');
show create table t1;
set names utf8;
create table t2 as select quote('a');
show create table t2;
set names utf8mb4;
create table t3 as select quote('a');
show create table t3;