My example wasn't complete. You need to wrap the cursor calls in BEGIN and END. Read the DECLARE docs for the minutiae. /Steve
pgsql-sql by date:
Соглашаюсь с условиями обработки персональных данных