Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1majAv-0002jh-Ax for psycopg@arkaria.postgresql.org; Wed, 13 Oct 2021 18:40:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1majAs-0004vd-LU for psycopg@arkaria.postgresql.org; Wed, 13 Oct 2021 18:40:22 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1majAr-0004us-Vz for psycopg@lists.postgresql.org; Wed, 13 Oct 2021 18:40:22 +0000 Received: from bumble.maple.relay.mailchannels.net ([23.83.214.25]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1majAn-0002we-0U for psycopg@postgresql.org; Wed, 13 Oct 2021 18:40:20 +0000 X-Sender-Id: cp7oy65bvo|x-authuser|paolo@paolodestefani.it Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 16641122933; Wed, 13 Oct 2021 18:40:14 +0000 (UTC) Received: from lu-shared04.cpanelplatform.com (100-96-17-22.trex.outbound.svc.cluster.local [100.96.17.22]) (Authenticated sender: cp7oy65bvo) by relay.mailchannels.net (Postfix) with ESMTPA id 6AD4F122B8F; Wed, 13 Oct 2021 18:40:12 +0000 (UTC) X-Sender-Id: cp7oy65bvo|x-authuser|paolo@paolodestefani.it Received: from lu-shared04.cpanelplatform.com ([UNAVAILABLE]. [107.189.4.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384) by 100.96.17.22 (trex/6.4.3); Wed, 13 Oct 2021 18:40:13 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: cp7oy65bvo|x-authuser|paolo@paolodestefani.it X-MailChannels-Auth-Id: cp7oy65bvo X-Towering-Average: 331278bd0554414d_1634150413801_4085102251 X-MC-Loop-Signature: 1634150413801:1130240549 X-MC-Ingress-Time: 1634150413801 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=paolodestefani.it; s=default; h=Content-Transfer-Encoding:Content-Type: Message-ID:References:In-Reply-To:Subject:Cc:To:From:Date:MIME-Version:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=RyIFMW0PwRGodL8RLyeCk4Gf/XmP7jz/8K59vD+NoWc=; b=bOEgFasdo+xZoKIP8GUsvcbYA+ RvwS53Ktfn5Na4OHM3NvgYi9CirrbZKO+EviHeINAuT7MxdQr1kUsJnG7Er8CzdyYrIMWWIK57/V9 JkfKsVuUFkt1+PukU5LhcLomwUui5X6iT2VEAdym2MLP1qb0qQVGugKI7SmPoPQhe9gHAepBZoc+k //+xEdarN0ydRM8JUEFXYk2L6z9y/BRyeQqyWUXup//7pS+jegyn+8q6jQAooDBoItak4iTQgY7/J vSdSk2LuyBP63qs8zgJZi+V6Hfo4rN2i/fg87YALkaFlUCi9Vy1IbdKnOtqhSpLUmMnSrJkrRCI4S NInxCqDw==; Received: from [::1] (port=41858 helo=lu-shared04.cpanelplatform.com) by lu-shared04.cpanelplatform.com with esmtpa (Exim 4.94.2) (envelope-from ) id 1majAd-00BgNj-Qs; Wed, 13 Oct 2021 20:40:07 +0200 MIME-Version: 1.0 Date: Wed, 13 Oct 2021 20:40:07 +0200 From: Paolo De Stefani To: Daniele Varrazzo Cc: Psycopg Subject: Re: psycopg3 transactions In-Reply-To: References: <9a99d2d110b121542d1ea0a05066858b@paolodestefani.it> <6683df3e65fe961aa478e61db7ad687d@paolodestefani.it> User-Agent: Roundcube Webmail/1.4.11 Message-ID: X-Sender: paolo@paolodestefani.it Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit X-AuthUser: paolo@paolodestefani.it List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Il 13/10/2021 15:46 Daniele Varrazzo ha scritto: > On Wed, 13 Oct 2021 at 15:21, Paolo De Stefani > 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