首页 > 解决方案 > 用于插入/更新的单表 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];
});

};

标签: sqlnode.jspostgresql

解决方案


推荐阅读