title: how to use COMMIT and ROLLBACK in a PostgreSQL function
body: <p>I am using three insert statements, and if there is an error in the third statement, I want to rollback the first and the second one. If there is no way to do this, please tell me a different approach to handle this in PostgresqQL.</p>
  
  <p>If I use <code>COMMIT</code> or <code>ROLLBACK</code>, I get an error.</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION TEST1 ()
     RETURNS VOID
     LANGUAGE 'plpgsql'
     AS $$
  BEGIN 
  
      INSERT INTO table1 VALUES (1);
  
      INSERT INTO table1 VALUES (2);
  
      INSERT INTO table1 VALUES ('A');
      COMMIT;
  EXCEPTION
     WHEN OTHERS THEN
     ROLLBACK;
  END;$$;
  </code></pre>
  
  <p>The above code is not working; <code>COMMIT</code> and <code>ROLLBACK</code> are not supported by PostgreSQL functions.</p>