Re: psycopg3 transactions

From: Paolo De Stefani <paolo(at)paolodestefani(dot)it>
To: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
Cc: Psycopg <psycopg(at)postgresql(dot)org>
Subject: Re: psycopg3 transactions
Date: 2021-10-13 18:40:07
Message-ID: debfe686f16f1e5c57a3aec7db8d4c33@paolodestefani.it
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

Il 13/10/2021 15:46 Daniele Varrazzo ha scritto:
> On Wed, 13 Oct 2021 at 15:21, Paolo De Stefani
> <paolo(at)paolodestefani(dot)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

In response to

Browse psycopg by date

  From Date Subject
Next Message Daniel Fortunov 2021-10-13 23:28:11 Re: psycopg3 transactions
Previous Message Daniele Varrazzo 2021-10-13 17:28:29 Re: psycopg3 transactions