From: | Paolo De Stefani <paolo(at)paolodestefani(dot)it> |
---|---|
To: | Psycopg <psycopg(at)postgresql(dot)org> |
Subject: | psycopg3 transactions |
Date: | 2021-10-11 18:01:09 |
Message-ID: | eb5cc5d20c520e32b5963a4044b70af1@paolodestefani.it |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | psycopg |
Hi all
In psycopg3 i read and understood the new transaction management
behaviour. With the use of context managers i have to do something like
this:
con = psycopg.connect()
with con.transaction():
with con.cursor() as cur:
cur.execute("INSERT INTO table VALUES (1, 2, 3);")
and this works as expected.
But if i don't need a transaction because i don't need to commit
anything i can do something like this:
with con.cursor() as cur:
cur.execute("SELECT * FROM table;")
BUT if a do a select without a transaction the next command that require
a transaction don't works until i do a specific commit
with con.transaction():
with con.cursor() as cur:
cur.execute("DELETE FROM table;")
the delete is effective only for the current connection, i mean other db
user continue to see the <table> without the delete command
modifications
Looks like the previous select statement (uncommited) block following
delete statement even if i use the with con.transaction() statement.
If a do a con.commit() everything works as expected.
That means i need to use a transaction even for a select statement.
I can't use autocommit connection in my application.
Is it correct or am i losing anything ???
--
Paolo De Stefani
From | Date | Subject | |
---|---|---|---|
Next Message | Daniele Varrazzo | 2021-10-11 19:03:58 | Re: psycopg3 transactions |
Previous Message | Daniele Varrazzo | 2021-10-05 22:03:18 | Re: How to build statically on Windows |