根據以下說法,數據由低優先級向高優先級轉化:
When an operator combines two expressions of different data types, the rules for data type precedence specify that the data type with the lower precedence is converted to the data type with the higher precedence.
部分數據類型優先級順序如下圖:
用mysql進行測試,結果卻不符合由低到高轉換的說法:
mysql> select*from testu;
+---+---+
| a | b |
+---+---+
| 1 | a |
| 2 | b |
+---+---+
2 rows in set
mysql> create table `ttt` select `a` from `testU` union select `b` from `testU`;
Query OK, 4 rows affected
Records: 4 Duplicates: 0 Warnings: 0
mysql> select*from `ttt`;
+---+
| a |
+---+
| 1 |
| 2 |
| a |
| b |
+---+
4 rows in set
mysql> desc `ttt`;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| a | varchar(40) | NO | | | |
+-------+-------------+------+-----+---------+-------+
1 row in set
從選出的結果來看,跟預計的由低優先級的varchar類型轉成int型的情況並未發生,恰恰相反。
這個還是沒弄懂是爲什麼。