As for UPDATE a few lines from several parameters in nodejs / pg , I need to run the following:
update portfolios p set votes = s.votes from unnest(array[(5, 1), (15, 1), (25, 2)]) s (votes int, id int) where p.id = s.id
where my array in unsest is $ 1, as follows:
update portfolios p set votes = s.votes from unnest($1) s (votes int, id int) where p.id = s.id
However, my array initially consists of objects, for example:
[{votes: 5, id: 1}, {votes: 15, id: 1}, {votes: 25, id: 2}]
I tried converting it with:
my_array = my_array.map(function(e) { return tuple(e.votes, e.id); });
But it fails.
I need to fix a compatible array with values ββfor use with pg and Client.query.
How can I convert my array of objects to javascript and postgresql unsest?