postgresql 遍历结果集

有一条语句返回一个结果集,就是有两条数据:
select count(d.id),e.aId from event e where e.status='A' group by e.aId;
1 2
4 3
返回的数据有两条,现在我想把它遍历赋值到$count 和$ aid 变量中怎么做呢?
我是想写一个存储过程,查到结果然后根据返回的结果,以$count $aid为条件更新数据

for循环2次,分别赋值