javascript - Sequelize 查询符合 $LIKE 的要求,但收到 ER_PARSE_ERROR

标签 javascript mysql sql database sequelize.js

我有一个名为 MedicalStaff 的表,以及一系列医生的电子邮件地址,我可以用它们来查询 MedicalStaff。我想使用 findAll 来查找与此数组的任何匹配项,它看起来像页面 here 中间描述的 $like : {$any: [array] }} 运算符。是执行此操作的最佳方法。

我有以下查询:

var address = ['BubGuy@mailinator.com', 'DumbTime@mailinator.com'];
sequelizeInstance.models.MedicalStaff.findAll({where: {email: {$like: { $any: address}}}})
    .then(function(doctors){
        console.log(doctors);
        ...
     }

并出现以下错误:

{ SequelizeDatabaseError: ER_PARSE_ERROR: You have an error in your SQL syntax; 
check the manual that corresponds to your MySQL server version for the right syntax
to use near '('BubGuy@mailinator.com','DumbTime@mailinator.com')' at line 1  
...
 code: 'ER_PARSE_ERROR',
 errno: 1064,
 sqlState: '42000',
 index: 0,
 sql: 'SELECT `name`, `email`, `password`, `salt`, `phoneNumber`, `position`, 
`authenticationCode`, `active`, `unassigned`, `resetPasswordToken`, 
`isVerified`, `resetPasswordExpires`, `createdAt`, `updatedAt`, `fk_id`, `fk_email` 
FROM `MedicalStaffs` AS `MedicalStaff` WHERE `MedicalStaff`.`email` 
LIKE ANY (\'BubGuy@mailinator.com\',\'DumbTime@mailinator.com\');' },

它指示解析错误(1064),但我不确定为什么,因为地址定义良好,并且我完全按照链接中的文档使用它。有什么想法吗?

最佳答案

我查看了 any subqueries 上的 mysql 文档它说:

Syntax:

operand comparison_operator ANY (subquery) operand IN (subquery) operand comparison_operator SOME (subquery) Where comparison_operator is one of these operators:

= > < >= <= <> !=

运算符列表甚至不包括 like 运算符。使用不带通配符的 like 运算符有点毫无意义,因为它们与简单的 = 非常相似(但不一样)。

我想说你需要 in() 运算符 ($in) 来将字符串与字符串列表进行比较。

关于javascript - Sequelize 查询符合 $LIKE 的要求,但收到 ER_PARSE_ERROR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42684953/

相关文章:

javascript - 更改点击事件上的 V 形

sql - 显示同一学期至少教授 2 门类(class)的所有教授的不同 ID

mysql - 无法为 Mysql 启用符号链接(symbolic link)

mysql - 根据其他 2 个关系从表中选择

sql - 使用 XMLTYPE 输出执行 Oracle 存储过程并将其捕获到 SSIS 变量中

javascript - 单个 onEdit 函数有效 - 多个相同的函数不起作用

javascript - 向右滑动时删除 div

javascript - 为什么这一小段 jQuery 会搞乱我的 JavaScript 的其余部分?

MySQL 作为 Linux (Ubuntu) 中 SQL Server 2008 的桥梁

mysql - 插入或更新查询是否会影响查询中未包含的索引列?