Why not use generate_series() queries to insert the appropriate number
of tuples, instead of a handful of INSERT lines each time? Since each
insert is a separate transaction, that would probably be faster.
Why do you have a plpgsql function just to create a cursor? Wouldn't it
be simpler to create the cursor in an SQL statement?
--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services