This is outdated code and solution. See modern at https://github.com/rin-nas/postgresql-patterns-library/tree/master/procedures/loop_execute