title: how does Rollback works with nested functions in Postgresql
body: <p>It is known that if Transactions encounter an error it rollbacks. </p>
  
  <p>But what happens when we have the following situation:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION A()
    RETURNS void AS
  $BODY$
      perform B();
      perform C();
  end;
  $BODY$
    LANGUAGE plpgsql VOLATILE    
  
  CREATE OR REPLACE FUNCTION C()
    RETURNS void AS
  $BODY$
      insert into table_C(pk_a,ab,ac)
      select id,name,phone
      from users
      where....
      perform E();
  
  end;
  $BODY$
    LANGUAGE plpgsql VOLATILE
  </code></pre>
  
  <p>what happens when I call <code>A()</code> and <code>C()</code> has <code>'duplicate key error'</code> on <code>INSERT</code> to <code>table_C</code> ? Will it rollback only <code>C()</code>? Or <code>A()</code> with all it's sub calls and changes will rollback as well?</p>
  
  <p>The rollback mechanism is defined per transactions... if I understood correctly transactions is a set of SQL queries. So how many transactions I have here? Is <code>PostgreSQL</code> choose the number of transactions by itself? each function is a transaction on its own?</p>