title: How to iterate over results of query
body: <p>I am creating a function in pgsql script language, and what I want to do in this point is iterate over the results of a query and for each row do something specific. My current try is the following, where <code>temprow</code> is declared as <code>temprow user_data.users%rowtype</code>. The code in question is the following:  </p>
  
  <pre><code>FOR temprow IN
          SELECT * FROM user_data.users ORDER BY user_seasonpts DESC LIMIT 10
      LOOP
          SELECT user_id,user_seasonpts INTO player_idd,season_ptss FROM temprow;
          INSERT INTO user_data.leaderboards (season_num,player_id,season_pts) VALUES (old_seasonnum,player_idd,season_ptss);
      END LOOP;  
  </code></pre>
  
  <p>However I get the following error from this: <code>ERROR:  relation "temprow" does not exist</code>. If it's clear what I want to be done, could you point to me the right way to do it?</p>