Skip to content

Instantly share code, notes, and snippets.

@justdoit0823
Created July 17, 2017 15:10
Show Gist options
  • Save justdoit0823/e64ff7bebb4285956fdf41ce999027e2 to your computer and use it in GitHub Desktop.
Save justdoit0823/e64ff7bebb4285956fdf41ce999027e2 to your computer and use it in GitHub Desktop.
Update same row multiple times in postgresql
drop table if exists s_multi_update_same_row;
create table s_multi_update_same_row(
id int,
count int
);
insert into s_multi_update_same_row select id, 0 from generate_series(1, 1000) as id;
update s_multi_update_same_row A set count = count + 1 from generate_series(1, 10000) as B(id) where A.id = B.id % 1000 + 1;
select id, count from s_multi_update_same_row limit 10;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment