运行node.js pg并且CTE upsert语句出现死锁问题。我在尝试运行查询语句时遇到了死锁。我想知道是否有办法锁定表(在node.js pg中),以便我不会遇到这个问题。
pg.connect(constring, function(err, client, done) {
if(err) { console.error('Error (updateHapiActivities: human_api_activities__c) connecting to DB ... : ' + err );
} else {
var queryConfig = "WITH upsert AS (UPDATE salesforce.human_api_activities__c SET calories__c = ($1), distance__c = ($2), steps__c = ($3), id__c = ($4), updatedat__c = ($5) WHERE userid__c = ($8) AND $
client.query(queryConfig, [new_cal, new_dis, new_step, wearable_id, update_time, date, create_time, user_id, source], function(err, result) {
if(err) { console.error('Error (updateHapiActivities: human_api_activities__c) updating query ... : ' + err);
} else {
var devArr = result.rows;
client.end();
}); // end upsert query
} // end else
}); // end connection
我尝试了一个client.query(“BEGIN;”)...然后在client.query之后(“LOCK表IN SHARE ROW EXCLUSIVE”......但是LOCK TABLE错误输出只能用于交易块。
任何帮助?