Anthony Chung
Anthony Chung

Reputation: 1477

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

Upvotes: 0

Views: 1039

Answers (1)

jcaron
jcaron

Reputation: 17710

Simply use ANY and pass the array:

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

Upvotes: 2

Related Questions