Skip to content

Instantly share code, notes, and snippets.

@onderkalaci
Created December 10, 2020 15:18
Show Gist options
  • Select an option

  • Save onderkalaci/1982a35da55c27b907308b453f9d9a17 to your computer and use it in GitHub Desktop.

Select an option

Save onderkalaci/1982a35da55c27b907308b453f9d9a17 to your computer and use it in GitHub Desktop.
create or replace procedure top_function()
language plpgsql
as
$$
begin
RAISE NOTICE 'Top function is called';
call second_function();
EXCEPTION
when others then
RAISE NOTICE 'Top function exception handling';
PERFORM * FROM users_table;
--call second_function();
end; $$;
create or replace procedure second_function()
language plpgsql
as
$$
declare
n integer:= 1000;
counter integer := 0 ;
begin
RAISE NOTICE 'Second function is called';
insert into users_table (user_id) SELECT i from generate_series(0,100)i;
loop
exit when counter = n ;
counter := counter + 1 ;
PERFORM user_id/0 FROM users_table as foo_second;
RAISE NOTICE 'Second function loop % finished', counter;
end loop;
EXCEPTION
when others then
RAISE NOTICE 'Second function exception handling';
call third_function();
end; $$;
create or replace procedure third_function()
language plpgsql
as
$$
begin
PERFORM count(*) FROM users_table as foo_third;
TRUNCATE users_table;
end; $$;
SELECT citus.mitmproxy('conn.allow()');
SELECT citus.mitmproxy('conn.onQuery(query="^TRUNCATE").reset()');
BEGIN;
SAVEPOINT s1;
call top_function();
ROLLBACK TO SAVEPOINT s1;
SELECT citus.mitmproxy('conn.allow()');
call top_function();
ROLLBACK;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment