Reputation: 3760
I have a database table with a Y/N flag in one column. I want to read all records where the flag is 'N' and after processing a record, set the flag to 'Y' in that record. Is it correct, and reasonable, to do this at the same time, using two separate connections? Or should I read the entire table first and update only after I'm done with the reading? What's the correct approach to this?
The database involved is Netezza, in case it matters.
Upvotes: 0
Views: 1042
Reputation: 4934
You should read first then update. Not asynchronsly. If the "select" part takes a long time, you should consider doing it batches. You can use a separate connections but should be confident you've completed your read.
Upvotes: 1
Reputation: 2559
Depends mostly on your design and needs.
How important is the flag? What if something goes wrong when you have set all flags before you have processed them... and so on.
Why you need two connections is out of my understanding, usually you have one connection you keep open. I don't know the blocks of Netezza but some system can also be made to do select and update at the same time.
You could do:
Upvotes: 1