简体   繁体   中英

postgresql transaction: check for query error

i'm writing a postgresql function implementing a transaction. this how the code looks like:

BEGIN TRANSACTION REPEATABLE READ
INSERT INTO table1 VALUES(value1, value2);
INSERT INTO table2 VALUES(value3);
COMMIT
END;

Now i need to check if one of the insert query return some kind of error for insert rollback. How can i do it?

Checking for, and handling errors, is good. Do it consistently. While transactions will automatically roll back, you may want to alert the user log the problem, or take other actions. This being said the transaction will roll back on its own if there is a database error.

On the other hand, if you need to roll back a transaction because of an application error (outside the database), you issue a ROLLBACK command.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM