What does Postgres do when BEGIN is run on a connection in autocommit mode?

Posted by DNS on Stack Overflow See other posts from Stack Overflow or by DNS
Published on 2010-03-19T15:32:46Z Indexed on 2010/03/20 22:21 UTC
Read the original article Hit count: 143

Filed under:
|
|
|
|

I'm trying to better understand the concept of 'autocommit' when working with a Postgres (psycopg) connection. Let's say I have a fresh connection, set its isolation level to ISOLATION_LEVEL_AUTOCOMMIT, then run this SQL directly, without using the cursor begin/rollback methods (as an exercise; not saying I actually want to do this):

INSERT A
INSERT B
BEGIN
    INSERT C
    INSERT D
ROLLBACK

What happens to INSERTs C & D?

Is autocommit is purely an internal setting in psycopg that affects how it issues BEGINs? In that case, the above SQL is unafected; INSERTs A & B are committed as soon as they're done, while C & D are run in a transaction and rolled back. What isolation level is that transaction run under?

Or is autocommit a real setting on the connection itself? In that case, how does it affect the handling of BEGIN? Is it ignored, or does it override the autocommit setting to actually start a transaction? What isolation level is that transaction run under?

Or am I completely off-target?

© Stack Overflow or respective owner

Related posts about postgresql

Related posts about python