title: Commit, savepoint, rollback to in PostgreSQL?
body: <p>Can someone please explain to me why does COMMIT in this function returns EXCEPTION ?</p>
  
  <pre><code>DECLARE
    XNar CURSOR (forDATE Varchar) IS 
     SELECT NARUCENO, ISPORUKA_ID FROM XDATA_NARUDZBE 
     WHERE TO_CHAR(XDATA_NARUDZBE.DATUM, 'DD.MM.YYYY') = forDATE;
   LastDate  DATE;
   OutResult INTEGER;
   curNAR    NUMERIC;
   curISP    VARCHAR;
   RXNar     RECORD; 
  BEGIN
  
   OutResult := 1;
  
   SELECT MAX(DATUM) INTO LastDate FROM XDATA_NARUDZBE;  
  
   FOR RXNar IN XNar(TO_CHAR(LastDate, 'DD.MM.YYYY')) LOOP
  
     IF (RXNar.NARUCENO &lt;&gt; 0) AND (RXNar.ISPORUKA_ID = 'R01') THEN
       UPDATE NARUDZBE SET ISPORUCENO = RXNar.NARUCENO 
        WHERE NARUDZBE.PP_ID  = RXNar.PP_ID
          AND NARUDZBE.ART_ID = RXNar.ART_ID
          AND NARUDZBE.ISPORUKA_ID = 'R01';
     END IF;
  
    END LOOP;
  
   COMMIT; &lt;--- ????
  
   RETURN OutResult;
  
   EXCEPTION
    WHEN OTHERS THEN
     OUTRESULT := 0;
     RAISE;    
     RETURN OutResult;
  
  END;    
  </code></pre>
  
  <p>and why I can not use ROLLBACK TO SavePoint when EXCEPTION block exists in function?</p>