Last active
August 29, 2015 14:06
-
-
Save lesovsky/ed4229fe6c4cbaeaf646 to your computer and use it in GitHub Desktop.
delete_test_data.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create or replace function delete_test_data(chunk int,sleep int) returns void as $$ | |
declare | |
chunk int := $1; | |
sleep_interval int := $2; | |
deleted_rows int; | |
begin | |
while deleted_rows != 0 or deleted_rows is null loop | |
delete from products where id in (select id from worktable order by id limit chunk); | |
delete from worktable where id in (select id from worktable order by id limit chunk); | |
get diagnostics deleted_rows := row_count; | |
perform pg_sleep(sleep_interval); | |
raise notice 'deleted % rows', deleted_rows; | |
end loop; | |
end; | |
$$ language plpgsql |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment