Home > Software engineering >  What does Postgresql ODBC AutoCommit mode really mean
What does Postgresql ODBC AutoCommit mode really mean

Time:09-25

Postgresql (via psql) seems to always auto commit after each statement unless a begin has been issued, in which case it commits on a commit/rollback. Fine.

But ODBC has an autocommit flag that says do it or don't. A mode on the transaction. That is a different model to using begins.

So how do they interact? Does ODBC autocommit actually send anything to the server, or does it just issue a hidden begin if set false? Suppose I have autocommit false, and then do

  -- autocommit = false in ODBC driver
  -- no explicit begin
  update 1;
  update 2;
  rollback;
  -- no begin
  update 4;
  update 5;
  rollback;

does update 4 get rolled back? I presume that the others all do get rolled back.

Please, no responses that say auto commit auto commits after every query. This is a (relatively) sophisticated question.

CodePudding user response:

Update 4 will get rolled back.

All clients that support "autocommit = off" implement that by sending an extra BEGIN to the server before the first statement after the end of a transaction. PostgreSQL itself is oblivious to that; it does not have a mode where autocommit is disabled.

  • Related