From: | Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com> |
---|---|
To: | Siddharth Jain <siddhsql(at)gmail(dot)com>, pgsql-general(at)lists(dot)postgresql(dot)org |
Subject: | Re: what happens if a failed transaction is not rolled back? |
Date: | 2023-04-24 15:45:03 |
Message-ID: | 89614320-852e-ce8d-7b01-2eff0e537e09@aklaver.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 4/24/23 08:43, Adrian Klaver wrote:
> 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
Forgot to add.
To get past above:
con.rollback()
cur.execute("select 1")
>
>
>
>>
>> thanks.
>>
>> S.
>
--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | David G. Johnston | 2023-04-24 15:46:49 | Re: what happens if a failed transaction is not rolled back? |
Previous Message | Adrian Klaver | 2023-04-24 15:43:14 | Re: what happens if a failed transaction is not rolled back? |