The calculations inside the loop are written in some dynamic high-level language and cannot easily be translated into SQL.
pgsql-hackers by date:
Соглашаюсь с условиями обработки персональных данных