On Wed, Jan 28, 2015 at 11:53 AM, Marc Mamin-2 [via PostgreSQL] <[hidden email]> wrote:
>In this case when an error occurs the rollback work only on the wrong query. The other insert are committed.
The rollback only takes place on the errored statement, because you are catching the exception. In order to ensure a complete rollback of your transaction (which may have started outside of your function), you'll need to rethrow an error after your exception handling.
The 9.4 documentation is in direct conflict with this statement...all persistent updates inside the associated BEGIN/END block should be rolled back.
Transactions MUST start "outside your function" by definition. By not re-throwing the exception any outer block (i.e., the one calling the function) would still end up intact but every statement inside of the function should rollback unless separate blocks are created to isolate the different statements.