Created
May 19, 2017 15:18
-
-
Save Komzpa/69fa1b7149f48e447c634b4bf171f1ce to your computer and use it in GitHub Desktop.
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
drop function if exists progressbar( double precision, double precision, timestamptz ); | |
create or replace function progressbar( | |
done_count float, | |
total_count float, | |
start_time timestamptz default now() | |
) | |
returns setof void | |
as $$ | |
declare | |
display_progressbar boolean; | |
begin | |
begin | |
display_progressbar = (select current_setting('progressbar.display') != 'off'); | |
exception when others | |
then begin display_progressbar = true; | |
end; | |
end; | |
if display_progressbar and total_count > 0 and done_count > 0 | |
then | |
raise warning '% %/% [%] Running: % ETA: % Per iteration: %', | |
to_char(100 * done_count / total_count, '999D9') :: text || '%', | |
to_char(done_count, '9999999'), | |
to_char(total_count, '9999999'), | |
repeat('*', (80 * done_count / total_count) :: int) :: char(80), | |
(clock_timestamp() - start_time), | |
(total_count - done_count) * (clock_timestamp() - start_time) / done_count, | |
(clock_timestamp() - start_time) / done_count; | |
end if; | |
end; | |
$$ | |
language 'plpgsql' immutable strict parallel safe; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment