title: 'exit when not found;' does not work and how to bypass that using smth like 'exit when cursor==''
body: <p>I am using a cursor, fetching one column 'email1' table 'pepe_emails' of 10 items. Inside the loop I try to append the content fetched in an array.</p>
  
  <p>There is a previous error that the one I mention in this post. By the way, Here the problem is the fetch loop, that becomes in an infinite loop, when using <em>'exit when not found;'</em>.
  I tried to bypass the <em>'exit when not found'</em>. But I did not get something similar as this idea: 'exit when cursor_emails == '';'. This is not right in postgresql but something like right written would work. at the output showed, here should break:</p>
  
  <pre><code>NOTICE:  Loop 10
  NOTICE:  Value: ()
  </code></pre>
  
  <p>Here is my current and failed code:</p>
  
  <pre><code>do $$
  declare
      cursor_emails cursor for
          select pepe_emails.email1
          from pepe_emails;
  
      arr_emails varchar[];
      table_record record;
      i integer := 0;
  
      begin
          raise notice 'Hola 1';
          open cursor_emails;
          loop
          raise notice 'Loop %', i;
          i = i + 1;
              fetch cursor_emails into table_record;
              raise notice 'Value: %', table_record;
              perform array_append (arr_emails, table_record::varchar);
              raise notice 'Value: %', arr_emails[-1];
          exit when not found;
          end loop;
  
      close cursor_emails;
  
      end;
  $$;
  </code></pre>
  
  <p>And this is the output of this code:</p>
  
  <pre><code>NOTICE:  Hola 1
  NOTICE:  Loop 0
  NOTICE:  Value: (us_1.gmail.com)
  NOTICE:  Value: &lt;NULL&gt;
  NOTICE:  Loop 1
  NOTICE:  Value: (us_2.gmail.com)
  NOTICE:  Value: &lt;NULL&gt;
  NOTICE:  Loop 2
  NOTICE:  Value: (us_3.gmail.com)
  NOTICE:  Value: &lt;NULL&gt;
  NOTICE:  Loop 3
  ...
  NOTICE:  Value: (us_9.gmail.com)
  NOTICE:  Value: &lt;NULL&gt;
  NOTICE:  Loop 9
  NOTICE:  Value: (us_10.gmail.com)
  NOTICE:  Value: &lt;NULL&gt;
  NOTICE:  Loop 10
  NOTICE:  Value: ()
  NOTICE:  Value: &lt;NULL&gt;
  NOTICE:  Loop 11
  NOTICE:  Value: ()
  NOTICE:  Value: &lt;NULL&gt;
  </code></pre>
  
  <p>Thanx in advance</p>