Re: psycopg3 transactions - Mailing list psycopg

From Paolo De Stefani
Subject Re: psycopg3 transactions
Date
Msg-id debfe686f16f1e5c57a3aec7db8d4c33@paolodestefani.it
Whole thread Raw
In response to Re: psycopg3 transactions  (Daniele Varrazzo <daniele.varrazzo@gmail.com>)
List psycopg
Il 13/10/2021 15:46 Daniele Varrazzo ha scritto:
> On Wed, 13 Oct 2021 at 15:21, Paolo De Stefani 
> <paolo@paolodestefani.it> wrote:
> 
>> I was used to wrote a "with con.cursor() as cur:" that now i hato to
>> replace with:
>> 
>> with con.transaction():
>>      with con.cursor() as cur:
>>          cur.execute("ANY SQL STATEMENT")
>> 
>> and everything works as expected (or i expect...)
> 
> You can even write:
> 
>     with con.transaction():
>         con.execute("ANY SQL STATEMENT")
> 
> But is it even useful to wrap a transaction around any single
> statement? I still think you'd be better off with an autocommit
> connection.

In my small application i use only one connection (per client). I manage 
the customer orders of a food stand. The orders have header and lines. 
In that case i do a commit only after insert/update of the 2 table's 
records so i can not use an autocommit connection.

But what i wrote before and your suggestion are just fine for my needs, 
thanks


-- 
Paolo De Stefani



psycopg by date:

Previous
From: Daniele Varrazzo
Date:
Subject: Re: psycopg3 transactions
Next
From: Daniel Fortunov
Date:
Subject: Re: psycopg3 transactions