Fwd: odd transaction behavior
Kerri Reno <[email protected]> Mon, 22 Mar 2010 11:44:32 -0600
| Newsgroups | gmane.comp.python.db.psycopg.devel |
|---|---|
| Message-ID | <[email protected]> |
Oops - I only sent this to Federico. ---------- Forwarded message ---------- From: Kerri Reno <[email protected]> Date: Mon, Mar 22, 2010 at 11:43 AM Subject: Re: [Psycopg] odd transaction behavior To: Federico Di Gregorio <fog-NGVKUo/i/[email protected]> Federico, Thanks for your response. Do you suggest that I change the isolation level back to READ COMMIT if I want to do multiple lines in a transaction? Kerri On Mon, Mar 22, 2010 at 11:39 AM, Federico Di Gregorio <fog-NGVKUo/i/[email protected]>wrote: > On 22/03/2010 17:43, Kerri Reno wrote: > > Hello all! I'm a newbie to this mailing list but I've been using > > psycopg for quite a while. I hope you can help me! > > > > I recently changed our isolation level from 'READ COMMIT' to > > 'AUTOCOMMIT' and have seen some odd behavior when I want to post a > > multiple line transaction. I am using > > > 'conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)' > > > > > in the connection class to make all transactions auto commit. Then I am > > using cursor.execute('BEGIN') to start a longer transaction. Is this > > what I should be doing? Because conn.commit() doesn't seem to work > > on these longer transactions. BUT, if I do cursor.execute('commit'), > > then the transactions are posted. Should conn.commit() work? If so, > > what am I doing wrong? This is a viable way to commit the data, but > > I'm just wondering if it is the 'correct' way. > > If you switch transactions off (by ISOLATION_LEVEL_AUTOCOMMIT) then you > have two options: > > 1) to not use transactions > 2) as you discovered, manage transactions by yourself issuing BEGIN, > COMMIT and ABORT commands using execute() > > Sincerely, I don't like (2). If you want transactions, choose the > appropriate transaction isolation level, be pythonic and let psycopg do > its work (it will start a transaction before your first query and just > after you call .commit() or .rollback() on the connection). > > If you decide to manage transactions by yourself then avoid to call > .commit() or .rollback(), because psycopg is not supposed to know what's > you're doing and won't oblige to your command. > > federico > > -- > Federico Di Gregorio fog-NGVKUo/i/[email protected] > I filosofi son come i sociologi: il mondo non lo capiscono. -- A.R.M. > > > _______________________________________________ > Psycopg mailing list > Psycopg-IAPFreCvJWPBWskQ1e/[email protected] > http://lists.initd.org/mailman/listinfo/psycopg > > -- If you have an emergency, and can't reach me, please call Craig at 928-257-4980 or the help desk at 928-502-4202. .·:*¨¨*:·. .·:*¨¨*:·. .·:*¨¨*:·. Yuma Educational Computer Consortium Compass Development Team Kerri Reno [email protected] (928) 502-4240 .·:*¨¨*:·. .·:*¨¨*:·. .·:*¨¨*:·. -- If you have an emergency, and can't reach me, please call Craig at 928-257-4980 or the help desk at 928-502-4202. .·:*¨¨*:·. .·:*¨¨*:·. .·:*¨¨*:·. Yuma Educational Computer Consortium Compass Development Team Kerri Reno [email protected] (928) 502-4240 .·:*¨¨*:·. .·:*¨¨*:·. .·:*¨¨*:·. _______________________________________________ Psycopg mailing list Psycopg-IAPFreCvJWPBWskQ1e/[email protected] http://lists.initd.org/mailman/listinfo/psycopg