public inbox for [email protected]
help / color / mirror / Atom feedFrom: Podrigal, Aron <[email protected]>
To: [email protected]
Subject: Proper way to keep count of statements executed within current transaction
Date: Fri, 24 May 2019 15:49:04 -0500
Message-ID: <CANJp-yjQ0G+ww_fMeWdNwYcprwZLQTxSvG8wTu8LKek26MTayQ@mail.gmail.com> (raw)
Hi
I've seen many libraries using psycopg2 wrapping execution of statements
and in case of connection failure, it reconnects and submits the query
again.
Doing so in every case can lead to unexpected results when the connection
was reset after the first statement within a transaction.
Consider the following:
BEGIN; -- or autocommit = False
SELECT balance FROM accounts WHERE id = 1 FOR UPDATE;
-- User code does some processing with the returned value.
-- At this point the the server was restarted and connection is closed
-- The users code submits
UPDATE accounts SET balance = x WHERE id = 1;
-- The UPDATE query fails due to lost connection, so the library code which
wraps the statement reconnects and submits the query again.
My question is, what is the correct way to detect whether any statements
were executed successfully prior to the connection being lost. And decide
whether it is safe to automatically reconnect and resubmit the query ?
--
-
Aron Podrigal
view thread (2+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected]
Subject: Re: Proper way to keep count of statements executed within current transaction
In-Reply-To: <CANJp-yjQ0G+ww_fMeWdNwYcprwZLQTxSvG8wTu8LKek26MTayQ@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox