title: Handling error with exception clause in postgreSQL
body: <p>I wrote this piece of code in PL/PGSQL.</p>
  <pre><code>    WHILE nbStatus1 &lt; nbStatus0 AND StatusExec = 1 LOOP
          BEGIN
          SELECT Id, query INTO idQuery, Selectquery FROM temp_table_test WHERE Status = 0 LIMIT 1;
          
      
          EXECUTE Selectquery;
          
          UPDATE temp_table_test
          SET Status = 1
          WHERE Id = idQuery;
          
          nbStatus1 := nbStatus1 + 1;
      
          EXCEPTION
              WHEN others THEN
                  UPDATE LOGS_TEST_DETAILS
                  SET ENDDATE = NOW(),
                      ERRORMESSAGE = SQLERRM,
                      ERRORCODE = SQLSTATE 
                  WHERE TRAITEMENTID = lastTraitementId AND QUERYID = idQuery;
              
                  StatusExec := 0;
              ROLLBACK;
          END;
          COMMIT;
      END LOOP;
  </code></pre>
  <p>I use EXECUTE to CALL a list of procedure, one after the other in the while loop.
  Each CALL is stored in the variable Selectquery.</p>
  <p>It works fine but...
  I'm trying to implement a kind of try catch in case i made a mistake in one of the procedure i call in the loop.</p>
  <p>So i did a mistake (on purpose) inside one of the procedure i call. But the ROLLBACK, remove all the changes i did, even before the while loop. it kinda propagates to all my code</p>
  <p>Is there a way to ROLLBACK only the changes that occured within the EXECUTE command and then exit the loop ?</p>
  <p>There is something to deal with savepoint i guess, but i can't sort it out</p>
  <p>Thanks for your help</p>