public inbox for [email protected]  
help / color / mirror / Atom feed
From: Paolo De Stefani <[email protected]>
To: Daniele Varrazzo <[email protected]>
Cc: Psycopg <[email protected]>
Subject: Re: psycopg3 transactions
Date: Wed, 13 Oct 2021 20:40:07 +0200
Message-ID: <[email protected]> (raw)
In-Reply-To: <CA+mi_8Z2FT4bHN1yTiM=aS8BXkbiZLwP=KLasXGQPgBRoDPrMg@mail.gmail.com>
References: <[email protected]>
	<CA+mi_8bXjHTrzDLQ+n_6K2MHVsr0J32X1HA28Ey9O+-Zm6JaeQ@mail.gmail.com>
	<[email protected]>
	<CA+mi_8afF2jMifiLSvL99+Ztupy1me7xDNAv0g47WxHWbwN9vw@mail.gmail.com>
	<[email protected]>
	<CA+mi_8Z2FT4bHN1yTiM=aS8BXkbiZLwP=KLasXGQPgBRoDPrMg@mail.gmail.com>

Il 13/10/2021 15:46 Daniele Varrazzo ha scritto:
> On Wed, 13 Oct 2021 at 15:21, Paolo De Stefani 
> <[email protected]> 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





view thread (28+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: psycopg3 transactions
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox