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 1maeb0-0001MU-Sp for psycopg@arkaria.postgresql.org; Wed, 13 Oct 2021 13:47:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1maeaz-00063E-SD for psycopg@arkaria.postgresql.org; Wed, 13 Oct 2021 13:47:01 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1maeaz-000636-KU for psycopg@lists.postgresql.org; Wed, 13 Oct 2021 13:47:01 +0000 Received: from mail-ua1-x92d.google.com ([2607:f8b0:4864:20::92d]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1maeax-0007rc-JI for psycopg@postgresql.org; Wed, 13 Oct 2021 13:47:01 +0000 Received: by mail-ua1-x92d.google.com with SMTP id e2so4574391uax.7 for ; Wed, 13 Oct 2021 06:46:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=OZKBRmonZluNecXei95tG78PyHVCItMADTisUFiHnNQ=; b=i8LJQoH1jXtVSF09EI7MAyDQxQkUp017ETxd4NTSvq8jP21Q1tt0Qj870asFvE6SZ4 EP7+tuBv8CDqmiI8CvHzpzwnEhcwwes6ZH4yWheRIkuUoYtkw8zT0yt6LhV5kRaIKpop 0UMeOuYUhVgCJuW5/EhcczV8OipUGxHUo6nQCZUWq/N8wNzxx+cQScuam8tHhgM6i7Ln 1bFgydyGwPdy37nuY2koYRgY7G5AHwBgocDt4a89X0T/a1FfVGlexVbxeSbVC0PDJCD3 E4ZXucnjuEQRKq9ltzw+CsA1HqteDIBHY6z9otJIyP/DnhRVsBggzVaeEQf5AP+rfjYD VgYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=OZKBRmonZluNecXei95tG78PyHVCItMADTisUFiHnNQ=; b=7VaWnX9eUizz4JpdsxcaXkaTRxgu1Yu6Jt5Qo8nk5pOAZgDR5QvQcMsw2ti6r0H+lf 0N7rVA3S+nzCLRFfUvC5nFO3rx1tDZVfVvh3/m4F913NJN8SE4uI8qpRGqe6sAN+sBzN QPMmEWT4JF/i0eh+evnlrWBRXaH2aQsu/BL24PyXgVO5nL5K+oonFU5Mpfc09hmYaFn+ SLUddQdyGpxUBj4tKoDwZoofdC24rY9Bx0z4fYvzTyLrBkjXDBkQTfYN34AyoIG7xhG3 pMsnDV9gtyKBQfxSR3W6Smv+rDl1rzvasv1GU7vHqJ37pJQW4uyzSl0/pNM8PHhGY/JV 8mTw== X-Gm-Message-State: AOAM533wv3mj0ulMHJfkNF7KtW79lI16+ye3DDM3jMuqmK/TssSPpq9E 4qwY1B2hpBqD7VhbVd59H4znGZCEddA0seaHTW8= X-Google-Smtp-Source: ABdhPJyO2O4V9/3VCzRWwYxZEXbHXj5AVhjQK/6tvV3HJPH2h0NuOGCiZ91rMVB9WlZURwRLNA4CVGQQPTEhLGAKKh4= X-Received: by 2002:ab0:4adc:: with SMTP id t28mr28885949uae.4.1634132817591; Wed, 13 Oct 2021 06:46:57 -0700 (PDT) MIME-Version: 1.0 References: <9a99d2d110b121542d1ea0a05066858b@paolodestefani.it> <6683df3e65fe961aa478e61db7ad687d@paolodestefani.it> In-Reply-To: <6683df3e65fe961aa478e61db7ad687d@paolodestefani.it> From: Daniele Varrazzo Date: Wed, 13 Oct 2021 15:46:46 +0200 Message-ID: Subject: Re: psycopg3 transactions To: Paolo De Stefani Cc: Psycopg Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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. -- Daniele