SHOW COLUMN转义机制

SHOW COLUMN escaping mechanism

我有一个名为 \'column 的专栏。我可以像在任何其他列中一样在 SELECT 语句中使用它。但是,当我尝试执行 SHOW COLUMNS FROM myTable LIKE '\''column' 时,我没有得到任何结果。我观察到如果我双重转义反斜杠它会起作用:'\\''column'.

我从 MariaDB 控制台对此进行了测试,但我也在 MySQL 8.

中观察到相同的行为

转义是如何工作的?我应该如何正确转义该值,以便我可以获取列信息?

DB Fiddle

来自mysql documentation

MySQL uses C escape syntax in strings (for example, \n to represent the newline character). If you want a LIKE string to contain a literal , you must double it. (Unless the NO_BACKSLASH_ESCAPES SQL mode is enabled, in which case no escape character is used.) For example, to search for \n, specify it as \n. To search for \, specify it as \\; this is because the backslashes are stripped once by the parser and again when the pattern match is made, leaving a single backslash to be matched against.