4

How can I execute a bulk update query in Golang? For example I want to execute these queries in one query.

update product set product_name='AAAA' where product_id='1'

update product set product_name='BBB' where product_id='2'

update product set product_name='CCC' where product_id='3'

update product set product_name='DDDD' where product_id='4'
Alexey S. Larionov
  • 6,555
  • 1
  • 18
  • 37
Nik-Khah
  • 51
  • 1
  • 5
  • When using postgres as the dbms then you can use [`update ... from`](https://stackoverflow.com/questions/18797608/update-multiple-rows-in-same-query-using-postgresql) and execute it as a single query: https://play.golang.org/p/OgPbOMkDHyV – mkopriva Aug 22 '20 at 14:25
  • There are various non-standard ways of doing this depending on what database software you are using. In MySQL, a popular choice is `INSERT INTO [...] ON DUPLICATE KEY UPDATE`. For complete example, see https://stackoverflow.com/a/450695/593146 – Zyl Aug 22 '20 at 16:35
  • Any solutions to this? – Robula Apr 12 '21 at 16:49

0 Answers0