create or replace function make_dump(scaling integer, single_transaction boolean) returns text as 
$$
    declare 
        ii              integer;
        jj              integer;
        kk              integer default 0;
        dump_sql        text;
        insert_lines    text default '';
        scaling_adj     integer;
        min_delta       integer default 1000;
    begin
        dump_sql := 'drop table bulk_insert; create table bulk_insert(id int, f text);\n';
        dump_sql := dump_sql || 'begin;\n';
        dump_sql := dump_sql || 'select timeofday(); \n';
        
        scaling_adj := scaling  / min_delta;
        
        for ii in 1..min_delta loop
            insert_lines := insert_lines || 'INSERT INTO bulk_insert VALUES (' || kk || 
                   ', \'' || kk || '\');\n';                
                   
           kk := kk + 1;                   
        end loop;
        
        kk := 0;
        
        for ii in 1..5 loop
            if ii > 1 and single_transaction = false then
                dump_sql := dump_sql || 'commit; begin;\n';   
            end if;
            
            for jj in 1..scaling_adj loop
                dump_sql := dump_sql || insert_lines;
                kk := kk + min_delta;                    
            end loop;
            
            raise notice '% rows added', kk;
            
            dump_sql := dump_sql || 'select timeofday(); \n';
        end loop;
        
        dump_sql := dump_sql || 'commit; \n';
        
        return dump_sql;       
    end;    

$$ language plpgsql;