title: PostgreSQL multi-row updates in Node.js
body: <p>As i already found here <a href="https://stackoverflow.com/questions/18797608/update-multiple-rows-in-same-query-using-postgresql">On Stackoverflow</a> it is possible to update multiple rows in one query by doing something like this</p>
  
  <pre><code>update test as t set
      column_a = c.column_a,
      column_c = c.column_c
  from (values
      ('123', 1, '---'),
      ('345', 2, '+++')  
  ) as c(column_b, column_a, column_c) 
  where c.column_b = t.column_b;
  </code></pre>
  
  <p>special thanks to @Roman Pekar for the clear answer.</p>
  
  <p>Now i'm trying to merge this way of updating with querying to a postgreSQL database in NodeJS. </p>
  
  <p>Here is a snipped of my code: </p>
  
  <pre><code>var requestData = [
      {id: 1, value: 1234}
      {id: 2, value: 5678}
      {id: 3, value: 91011}
  ]
  
  
  client.connect(function (err) {
      if (err) throw err;
  
  client.query(buildStatement(requestData), function (err, result) {
      if (err) throw err;
  
      res.json(result.rows);
  
      client.end(function (err) {
          if (err) throw err;
      });
  });
  });
  
  
  var buildStatement = function(requestData) {
  var params = [];
  var chunks = [];
  
  for(var i = 0; i &lt; requestData.length; i++) {
  
      var row = requestData[i];
      var valuesClause = [];
  
      params.push(row.id);
      valuesClause.push('$' + params.length);
      params.push(row.value);
      valuesClause.push('$' + params.length);
  
      chunks.push('(' + valuesClause.join(', ') + ')');
  
  }
  
  return {
      text: 'UPDATE fit_ratios as f set ratio_budget = c.ratio_budget from (VALUES ' +  chunks.join(', ') + ') as c(ratio_label, ratio_budget) WHERE c.ratio_label = f.ratio_label', values: params
          }
  }
  </code></pre>
  
  <p>i don't get an error but it doesn't update my table, i don't really know what goes wrong here. Perhaps a syntax error in my query code? I just don't find any specific examples of multiple row querying when updating in NodeJS pg package</p>