The most efficient way to do this in Postgres is using UNNEST
. This lets you pass one parameter per column (rather than number of rows x number of columns). For your example, this would look like:
UPDATE table
SET
column_a=bulk_query.updated_column_a,
column_b=bulk_query.updated_column_b
FROM
(
SELECT * FROM UNNEST(
?::TEXT[],
?::TEXT[],
?::INT[]
) AS t(id, updated_column_a, updated_column_b)
) AS bulk_query
WHERE
users.id=bulk_query.id
Then you can pass three parameters:
[
["1", "2"],
["FINISH", "UNFINISH"],
[1234, 3124]
]
The great thing about this approach, is that you only need those 3 parameters no matter how many rows you want to update.
I've written more about this topic in this blog post: https://www.atdatabases.org/blog/2022/01/21/optimizing-postgres-using-unnest#update-multiple-records-to-different-values-in-a-single-query