Richard Kut <rkut(at)intelerad(dot)com> writes:
> and that works as expected. However, if I get an error within the transaction
> anywhere after the SAVEPOINT command, then the entire transaction fails, and
> any changes made prior to the SAVEPOINT are rolled back.
Only because you deliberately told the system to roll back the entire
transaction. You want to use ROLLBACK TO SAVEPOINT instead.
regards, tom lane