Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transaction roll back not working in Postgresql

I am working on PostgreSQL 9.1.4 .

I am inserting the data into 2 tables its working nicely.

I wish to apply transaction for my tables both table exist in same DB. If my 2nd table going fail on any moment that time my 1 st table should be rollback.

I tried the properties in "max_prepared_transactions" to a non zero value in /etc/postgres/postgres.conf. But Still Transaction roll back is not working.

like image 902
Kanchetianeel Avatar asked Apr 24 '26 19:04

Kanchetianeel


1 Answers

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;
like image 169
smn_onrocks Avatar answered Apr 27 '26 11:04

smn_onrocks