当标识符不是保留字或带有空格时,为什么我必须使用 BACKTICKS?

Why do I have to use BACKTICKS when identifier is not a reserved word or with spaces?

反引号没有错误。

DB [XXX]> create temporary table `123456e6` (`id` char (8));
Query OK, 0 rows affected (0.03 sec)

不使用反引号时出错。

DB [XXX]> create temporary table 123451e6 (`id` char (8));
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '123451e6 (`id` char (8))' at line 1

我的标识符 123451e6 根据页面 here 有效,并且不是保留字或空格或包含任何特殊字符。

您遇到了 "digit only" 规则的微妙情况:

Identifiers may begin with a digit but unless quoted may not consist solely of digits.

e字符用于数字的科学计数,MySQL将123451e6解释为“123451 * 106”或123451000000。任何其他字母但 "e" 会导致字符串遵守 "not digits only" 规则并且可以不加引号使用。例如:

MariaDB [db]> create temporary table 123451f6 (`id` char (8));
Query OK, 0 rows affected (0.02 sec)

它无效,因为 12345e6 形式的内容求值为数字,在此示例中具体为 12345 * 106。因此,您必须将其显式标记为字符串。