I have a Python script that will retrieve a batch of rows from a table in a remote Postgresql database, do some processing, and then store the result back to the database. I will have this script running concurrently on several different machines, so I need to make sure that two different instances of the script do not retrieve the same row from the table.
I can use SELECT ... FOR UPDATE, but I would still need to store, perhaps in a column of that table or in a different table, that those rows are being "worked on". If one instance of the script retrieves a batch of rows and starts processing them, another instance of the script could retrieve some of the same rows, unless I keep track of which rows are in progress.
What I need to do is retrieve a batch of rows AND update a table all in one atomic step.