sql - 用于插入/更新的单表 sql 查询返回无表关系的错误,我该如何修复此语句?
问题描述
我正在尝试创建一个只能保存一行信息的表格(“食物”),但会不断更新而不是添加。我正在使用 node.js 和一个相邻的 Javascript 文件,该文件将我的 db 请求保存到 sql,但这个请求一直失败。我知道这是我的查询而不是服务器的问题(即我正在成功记录参数)。任何人都可以帮忙吗?
exports.insertFood = function(
userid,
tageskarte1,
preis1,
description1,
tageskarte2,
preis2,
description2,
tageskarte3,
preis3,
description3,
timeVal
) {
console.log("is it REALLY getting to food?", userid);
const q = `
INSERT INTO food (userid, tageskarte1, preis1, description1, tageskarte2, preis2, description2, tageskarte3, preis3, description3, timeval)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)
ON CONFLICT (userid)
DO UPDATE SET tageskarte1=$2, preis1=$3, description1=$4,
tageskarte2=$5, preis2=$6, description2=$7,
tageskarte3=$8, preis3=$9, description3=$10, timeVal=$11
RETURNING *
`;
const params = [
userid,
tageskarte1,
preis1,
description1,
tageskarte2,
preis2,
description2,
tageskarte3,
preis3,
description3,
timeVal
];
return db.query(q, params).then(results => {
console.log(results.rows[0]);
return results.rows[0];
});
};
解决方案
推荐阅读
- javascript - 如何显示正确的值?不和谐.js
- angular - 我如何在 Angular 中使用 recaptcha v3?
- java - java中的int和char连接
- python - 优化 zarr 数组处理
- r - 是否有可能导出存储在 R 中两个列表中的 data.frames?
- javascript - Webpack 无法解析 scss/css 的 @import
- python - 想在python中添加“你想关闭程序”警告消息
- arrays - SetInterval 每次在 React Js 中显示默认状态值
- python - 如何以递增的顺序对文件进行排序,然后合并它们
- ruby - 切换 Ruby 版本