Re: psycopg3 transactions

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

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.

-- Daniele

In response to

Responses

Browse psycopg by date

  From Date Subject
Next Message Daniele Varrazzo 2021-10-13 13:56:14 Re: Using standard SQL placeholders in PG
Previous Message Paolo De Stefani 2021-10-13 13:20:54 Re: psycopg3 transactions