in postgresql you cannot write commit or roll back explicitly within a function. I think you could have use a begin end block just write it simple
BEGIN;
insert into tst_table values ('ABC');
Begin
insert into 2nd_table values ('ABC');
EXCEPTION
when your_exception then
ROLL BACK;
END;
END;