There is no set variables in plpgsql. If you want to retrieve set of rows for futher manipulation either use a CURSOR or ARRAY:
I believe what you want to achieve can be done with simple query result looping:
pgsql-novice by date:
Соглашаюсь с условиями обработки персональных данных