Home Ask Login Register

Developers Planet

Your answer is one click away!

Anthony Chung February 2016

Update Postgres rows using an array from client using Node.JS

I am receiving an array of values from the client(CLIENT) in Node and would like to update all rows whose R_ID column matches my array.

Other than iterating over the array and updating each looked up element in turn, is there any way for me to do the following?

  1. SELECT all records whose R_ID column matches a value from CLIENT
  2. UPDATE all records in column BOOL from FALSE to TRUE

Any ideas?

Thank you


jcaron February 2016

Simply use ANY and pass the array:

client.query("UPDATE some_table SET some_column=true WHERE id = ANY($1)",[array], function (err, result) ...

Post Status

Asked in February 2016
Viewed 1,843 times
Voted 11
Answered 1 times


Leave an answer

Quote of the day: live life