How should I end a transaction with possibly failed queries?
От | Sergey Samokhin |
---|---|
Тема | How should I end a transaction with possibly failed queries? |
Дата | |
Msg-id | e42595410909021218x1c93f8e2ic59b69f5b51f056c@mail.gmail.com обсуждение исходный текст |
Ответы |
Re: How should I end a transaction with possibly failed queries?
|
Список | pgsql-novice |
Hello. Does it seem right to send "COMMIT" without checking whether any of the queries I've done in the transaction failed? Here is pseudo code illustrating this behaviour where "COMMIT" is always sent no matter what result of do_some_queries() was: some_transaction(Conn) { query(Conn, "BEGIN"), try do_some_queries(Conn) catch Reason -> Reason after query(Conn, "COMMIT") end } Is this correct? What if there is a select from non-existing table inside do_some_queries()? Should I detect it (e.g. by thrown an exception) and do ROLLBACK as the following code does: some_transaction(Conn) { try query(Conn, "BEGIN"), do_some_queries(Conn), query(Conn, "COMMIT") catch Reason -> query(Conn, "ROLLBACK"), Reason end } First sample seems more elegant, but I'm not sure that it's safe. Will there be any problems with this in the future? Thanks. -- Sergey Samokhin
В списке pgsql-novice по дате отправления: