title: Cursor based records in PostgreSQL
body: <p>I'm trying to use cursors for a query that joins multiple tables. I've seen that for oracle there is a cursor based record. When I try the same for Postgres, it throws some error. How can I do the same in Postgres?</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION avoidable_states()
  RETURNS SETOF varchar AS
  $BODY$
  DECLARE
      xyz CURSOR FOR select * from address ad
                              join city ct on ad.city_id = ct.city_id;    
      xyz_row RECORD;
  BEGIN   
      open xyz;
  
      LOOP
      fetch xyz into xyz_row;
          exit when xyz_row = null;
          if xyz_row.city like '%hi%' then
              return next xyz_row.city;               
          end if;
      END LOOP;
      close xyz;  
  END;
  $BODY$
    LANGUAGE plpgsql VOLATILE;
  </code></pre>
  
  <p>Error I get is:</p>
  
  <blockquote>
  <pre><code>ERROR:  relation "xyz" does not exist
  CONTEXT:  compilation of PL/pgSQL function "avoidable_states" near line 4
  </code></pre>
  </blockquote>