gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 22:20:37 27 4
gpt4 key购买 nike

我有一个构造如下的 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]

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

最佳答案

MERGE 不被 MySQL 支持,对应的是

INSERT ... ON DUPLICATE KEY UPDATE

关于mysql - 合并语句中的 Node.js mysql 语法错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36712106/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com