2 ms·
Postgres bulk update: http://sqlfiddle.com/#!17/b3d19/1 http://sqlfiddle.com/#!17/b3d19/1 You can do something similar in MySQL with temp tables. Bulk update
by Beanis 9y ago
Postgres bulk update:
http://sqlfiddle.com/#!17/b3d19/1 http://sqlfiddle.com/#!17/b3d19/1
You can do something similar in MySQL with temp tables.
Bulk update through upsert (slightly different than a bulk update, since it can create rows too)
MySQL:
http://sqlfiddle.com/#!9/a6f050/1 http://sqlfiddle.com/#!9/a6f050/1
Postgres:
http://sqlfiddle.com/#!17/a8367/1 http://sqlfiddle.com/#!17/a8367/1
- adrianmonk 9y agoOK, so SQL extensions, so just the usual reasons to do bulk changes. I thought they might have mentioned it here because there was something unique to say about it in the context of this problem.
- imtringued 9y agoAnd preferably you use the postgres specific "unnest(array1, array2, ...)" function which turns array parameters passed into the query into a temporary table that you can query. UPDATE example SET position = CAST(temp.position AS INTEGER) FROM unnest(:ids, :positions) AS temp (id, position) WHERE example.id = CAST(temp.id AS INTEGER);