简体   繁体   中英

MYSQL - syntax error, unexpected '@', expecting $end

I'm trying to write a full-text search with the following SQL syntax:

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
  • u.usuario stores userID's string value
  • u.nombre stores user's full name
  • u.terminos stores some concatenated values to be used with AGAINST

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'

Note Sometimes user id can be an email, for that reason, it would have '@' character. When AGAINST value contains '@' I'm getting this error:

Syntax error, unexpected '@', expecting $end

Thanks very much.

Put the phrase in double-quotes inside the single-quoted string.

I tested this on 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 :

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".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM