Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

201
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda