title: Loop through columns of RECORD
body: <p>I need to loop through type <code>RECORD</code> items by key/index, like I can do this using array structures in other programming languages.</p>
  
  <p>For example:</p>
  
  <pre><code>DECLARE
      data1    record;
      data2    text;
  ...
  BEGIN
  ...
  FOR data1 IN
      SELECT
          *
      FROM
          sometable
  LOOP
  
      FOR data2 IN
          SELECT
              unnest( data1 )   -- THIS IS DOESN'T WORK!
      LOOP
          RETURN NEXT data1[data2];   -- SMTH LIKE THIS
      END LOOP;
  
  END LOOP;
  </code></pre>