[英]MYSQL - syntax error, unexpected '@', expecting $end
I'm trying to write a full-text search with the following SQL syntax:我正在尝试使用以下 SQL 语法编写全文搜索:
SELECT u.usuario AS `id`,
Concat('(', u.usuario, ') ', u.nombre) AS `text`
FROM usuarios AS u
WHERE u.cuenta_id = 10
AND MATCH (u.terminos) against ('jacuna@sgc.gov.co' IN boolean mode)
ORDER BY u.usuario ASC
LIMIT 50
Example:例子:
if a user has the id '123456' and full name 'john doe' , the MySQL column 'terminos' will contain id + full name which means '123456 john doe'如果用户具有 id '123456'和全名'john doe' ,则 MySQL 列 'terminos' 将包含id + 全名,这意味着 '123456 john doe'
Note Sometimes user id can be an email, for that reason, it would have '@' character.注意有时用户 ID 可以是电子邮件,因此,它会有“@”字符。 When AGAINST value contains '@' I'm getting this error:
当AGAINST值包含 '@' 时,我收到此错误:
Syntax error, unexpected '@', expecting $end
语法错误,意外的“@”,期待 $end
Thanks very much.非常感谢。
Put the phrase in double-quotes inside the single-quoted string.将短语放在单引号字符串内的双引号中。
I tested this on MySQL 5.6:我在 MySQL 5.6 上对此进行了测试:
mysql> SELECT u.usuario, terminos
FROM usuarios AS u
WHERE u.cuenta_id = 10 AND
MATCH (u.terminos) AGAINST ('"jacuna@sgc.gov.co"' IN BOOLEAN MODE);
+---------+------------------------+
| usuario | terminos |
+---------+------------------------+
| 1 | call jacuna@sgc.gov.co |
+---------+------------------------+
Read https://dev.mysql.com/doc/refman/8.0/en/fulltext-boolean.html :阅读https://dev.mysql.com/doc/refman/8.0/en/fulltext-boolean.html :
A phrase that is enclosed within double quote (") characters matches only rows that contain the phrase literally, as it was typed. The full-text engine splits the phrase into words and performs a search in the FULLTEXT index for the words. Nonword characters need not be matched exactly: Phrase searching requires only that matches contain exactly the same words as the phrase and in the same order. For example, "test phrase" matches "test, phrase".
包含在双引号 (") 字符中的短语仅匹配按字面意思键入的包含该短语的行。全文引擎将短语拆分为单词并在 FULLTEXT 索引中搜索单词。非单词字符不需要完全匹配:短语搜索只需要匹配包含与短语完全相同的单词并且顺序相同。例如,“测试短语”匹配“测试,短语”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.