nodejs+PostgreSQL一条语句批量更新多条数据

单更新是

UPDATE accounts SET balance=$2,count=$3 WHERE account=$1

多条更新使用下面语句即可

let batchUpdateSql="update transaction set is_free=tmp.is_free , is_stable=tmp.is_stable , is_fork=tmp.is_fork , is_invalid=tmp.is_invalid , is_fail=tmp.is_fail , is_on_mc=tmp.is_on_mc from (values " +
    "('B5956299E1BC73B23A56D4CC1C58D42F2D494808FBDEE073259B48F571CCE97C',false,false,false,false,false,false)," +
    "('5F2B6FA741A33CDD506C5E150E37FCC73842082B24948A7159DFEB4C07500A08',false,false,false,false,false,false)" +
    ") as tmp (hash,is_free,is_stable,is_fork,is_invalid,is_fail,is_on_mc) where transaction.hash=tmp.hash";
pgclient.query(batchUpdateSql, (res) => {
    //ROLLBACK
    console.log(res);
});

~~

未经允许不得转载:朱邦邦的博客 » nodejs+PostgreSQL一条语句批量更新多条数据

赞 (0)

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址