Re: what happens if a failed transaction is not rolled back? - Mailing list pgsql-general

From Adrian Klaver
Subject Re: what happens if a failed transaction is not rolled back?
Date
Msg-id d02fa181-e7a7-75bb-57ce-097c09835cb4@aklaver.com
Whole thread Raw
In response to what happens if a failed transaction is not rolled back?  (Siddharth Jain <siddhsql@gmail.com>)
Responses Re: what happens if a failed transaction is not rolled back?
List pgsql-general
On 4/24/23 08:37, Siddharth Jain wrote:
> Hi All,
> 
> i understand when writing application code, we should rollback a 
> transaction that fails to commit. this is typically done in the catch 
> block of a try-catch exception handler. but what if the developer does 
> not rollback the transaction? what happens in that case?
> 
> note that i am not asking: what happens if a transaction is not rolled back?
> i am asking: what happens if a /failed/ transaction is not rolled back?
> 
> failed transaction = you try to commit it but get an exception back from 
> the database.

In Python:

import psycopg2
con = psycopg2.connect("dbname=test host=localhost  user=postgres")
cur = con.cursor()
cur.execute("select 1/0")
DivisionByZero: division by zero

cur.execute("select 1")
InFailedSqlTransaction: current transaction is aborted, commands ignored 
until end of transaction block



> 
> thanks.
> 
> S.

-- 
Adrian Klaver
adrian.klaver@aklaver.com




pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: [EXT] Re: SCROLLABLE/UPDATABLE cursor question
Next
From: Adrian Klaver
Date:
Subject: Re: what happens if a failed transaction is not rolled back?