使用Node.js更新PostgreSQL数据库 [英] Update PostgreSQL database with Node.js

查看:223
本文介绍了使用Node.js更新PostgreSQL数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更新PostgreSQL表,因此要创建两个数组:

I am trying to update a PostgreSQL table so for that I'm creating two arrays:

var name_ = []; 
var id_ = [];

然后我创建一个forEach循环,其中MyRow是包含不同数据的查询:

Then I create a forEach loop where MyRow is a query that contains different data:

MyRow.rows.forEach(function(row){
    name_.push(row.name);
    id_.push(row.id);
});
var updateAccount = 'UPDATE myTable SET myRow =$1 '+
    'where id = $2'
client.query(updateAccount,[name_.toString(),id_.toString()],false).then(function(err,result){
    if (err) {
        console.log(err.stack);
    } else {
        console.log(name_)
    }
});

然后我得到一个错误:

错误:表"myTable"

error: missing FROM-clause entry for table "myTable "

推荐答案

我不确定该错误是否与之相关,但是在何处提到shema?还要在模板字符串上使用反引号, oneLine const.

I'm not sure the error is related, but where is shema mentioned? Also use backticks, oneLine and const on template strings.

const updateAccount = oneLine`
   UPDATE myTable
   SET myRow = $1
   WHERE shema.id = $2  -- where is `shema` defined?
`;

这篇关于使用Node.js更新PostgreSQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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