合并语句中的Node.js mysql语法错误?

时间:2016-04-19 07:59:44

标签: mysql node.js

我有一个构造如下的SQL查询:

tmpQUERY = "INSERT INTO vertix_users (user_name, user_email, user_pass) " +
    "VALUES (" + mysql.escape(userName) +
    ", " + mysql.escape(userEmail) + 
    ", " + mysql.escape(userPass) + ")";

tmpQUERY = "MERGE vertix_users WITH (HOLDLOCK) AS oldData " +
    "USING (VALUES (@user_name, @user_email)) AS newData (" + mysql.escape(userName) + ", " + mysql.escape(userEmail) + ") " +
    "ON newData.user_name = oldData.user_name AND newData.user_email = oldData.user_email " +
    "WHEN NOT MATCHED BY TARGET THEN " + tmpQUERY;

当我执行代码时,我得到以下日志:

MERGE vertix_users WITH (HOLDLOCK) AS oldData USING (VALUES (@user_name, @user_email)) AS newData ('asfasfsaff vvv', 'asfasfasfasf') ON newData.user_name = oldData.user_name AND newData.user_email = oldData.user_email WHEN NOT MATCHED BY TARGET THEN INSERT INTO vertix_users (user_name, user_email, user_pass) VALUES ('asfasfsaff vvv', 'asfasfasfasf', 'saqqq')

一个sql语法错误,内容如下:

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 'MERGE vertix_users WITH (HOLDLOCK) AS oldData USING (VALUES (@user_name, @user_e' at line 1]

没有合并的简单插入语句可以正常工作,但只要我添加该代码的第二部分,就会产生该错误。

1 个答案:

答案 0 :(得分:0)

MERGE不支持

MySQL,相当于

<强> INSERT ... ON DUPLICATE KEY UPDATE