Perhaps I'm misunderstanding the issue, but shouldn't you tell Postgres that you want to return a record when you are returning a record?
At the bottom you have:
RETURN rec;
While in the function definition you say:
RETURNS void
Besides that, you are returning 1 result (return ends the function) so it won't return anything beyond the first element anyhow.
I would guess you need something like this instead:
RETURNS SETOF record
And instead of RETURN rec
you would need:
RETURN NEXT rec
Since you want to return an integer, not sure if you actually want or need a RECORD
to return.