Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

192
Views
Version control using timestamp

I have a database DB with table T (id int, version timestamp) and application APP that works with this database and table. What I need to do:

  1. Lock table T.
  2. Select some rows from table T.
  3. Get current time curTimeStamp.
  4. Unlock table T.
  5. All rows thar are updated after unlocking tables (#4) must have version > curTimeStamp. Their version is set in UPDATE statement using SQL functions, for example, now(), current_timestamp() etc. I mean UPDATE T SET version=now();

After reading a lot of information I think about such solution:

  1. Start SQL transaction with read committed isolation level.
  2. Execute SELECT statement to get rows of table T
  3. Execute SELECT to get curTimeStamp.
  4. Commit SQL transcation.

However, some RDMS, for example H2 and Posgtresql return same value of now() functions inside one transaction. And as I understand then if some update transaction started before my select transaction AND update transaction finished after select transaction then row.version will be < curTimeStamp.

I am not very good in SQL transactions and I have doubts about my solution. Is this solution correct? If not, please, show my mistakes and right direction.

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!