I need to implement the solution given below (from Stackoverflow) to update multiple rows in a single query. The solution is:
update test as t set column_a = c.column_a from (values ('123', 1), ('345', 2) ) as c(column_b, column_a) where c.column_b = t.column_b;
How do I pass the multiple values to the query? I created a values string:
values_str = "('123', 1), ('345', 2)"
and used the following query:
res = DBCONN.query_one?(" UPDATE test as t SET column_a = c.column_a FROM ( VALUES $1 ) as c(column_b, column_a) WHERE c.column_b = t.column_b RETURNING id", values_str, as: String)
This query gives an error
syntax error at or near "$1"
How do I pass the multiple values in this query?
Thank you for your help.