CREATE TABLE ... SELECT behaviour when converting a value.
I trying to understand the following situation.
You can create a table based on a SELECT statement. This will look something like this.
mysql> CREATE TABLE employees SELECT CONVERT('Frank', CHAR(5)) AS name;
This will result in the following table:
mysql> DESCRIBE employees;
+-------+------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------+------+-----+---------+-------+
| name | varchar(5) | NO | | | |
+-------+------------+------+-----+---------+-------+
The thing I do not understand is the column name being VARCHAR(5) instead of being a CHAR(5). It seems like the datatype of the converted value 'Frank' to a CHAR(5) value is somehow interpreted as a VARCHAR(5) after the explicit conversion to CHAR(5).
I checked the documentation for the CONVERT method, and CHAR[(n)] is one of the available types that the CONVERT function accepts. (see:
https://dev.mysql.com/doc/refman/5.6/en/cast-functions.html#function_convert)
Can somebody explain this behaviour to me?
host OS: Debian
MySQL version: mysql Ver 14.14 Distrib 5.6.42, for Linux (x86_64)
Default storage engine: InnoDB
@@sql_mode = '';