使用Node.js在Mysql查询中传递数组 [英] Pass array in Mysql query with nodejs

查看:601
本文介绍了使用Node.js在Mysql查询中传递数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的查询,我想传递一个包含5个项目的数组.我正在使用mysql模块,因此我知道它可以完成,但是没有正确执行synatx,因此出现语法错误.

I have a simple query that I want to pass an array inside which has 5 items. I am using the mysql module so I know it can be done but am not doing the synatx right and therefore getting a syntax error.

以下是查询:

`UPDATE table1 SET table1.col=0 WHERE (table1.col2) IN = (?) AND table1.id=(SELECT ...);`,[arr]

//arr = [1,2,3,4,5];

我尝试过:

`UPDATE table1 SET table1.col=0 WHERE (table1.col2) IN = (?,?,?,?,?) AND table1.id=(SELECT ...);`,[arr]`

但是我仍然遇到语法错误.

but I still get a syntax error.

推荐答案

IN()谓词的语法不使用=.

WHERE (table1.col2) IN = (?,?,?,?,?)

应该是

WHERE table1.col2 IN (?,?,?,?,?)

提示:您可以(并且应该)在文档中自行检查语法,因此与发布到Stack Overflow相比,您可以更轻松地获得答案.

Tip: you can (and should) check syntax yourself in the documentation, so you can get answers more easily than posting to Stack Overflow.

https://dev.mysql.com /doc/refman/5.7/en/comparison-operators.html#function_in

这篇关于使用Node.js在Mysql查询中传递数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆