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

139
Visualizações
Strategy of updating multiple tables in postgresql

I am new to postgresql and I need help on strategy on when a large processing is being executed.

I have table which holds invoices, The records in this invoice table need to be 'posted' to multiple tables say sales table and also income table. This invoice table will be access by multiple users at the same time and when a user 'post' a particular record in the invoice table I want to prevent other users from making changes and 'posting' until the 'posting' is finished by the first user. How should i do it properly? Should I wrap the 'posting' in a transaction?

Thanks


Thanks Stepel and Landa for replying and sorry for not being clear.

Here's the coding that I am currently using in Foxpro.

Select InvHeader
If !Rlock()
 Return
EndIf

Select InvDetail
Scan
 do processing and verification 
 ..
 Insert Into tAr ... &&& temporary AR table
 Insert Into tGl ... &&& temporary GL table

EndScan

*** the reason I am using temporary table is that at this stage, the use may 
print out the detail of invoices that are to be posted and can then decide 
whether to proceed to commit the transaction.

Select InvHeader
Replace InvHeader.Posted With .T.

Select tAr
Scan
 do processing ...
 Insert Into Ar (....
EndScan

Select tGl
Scan
 do processing ...
 Insert Into GL ( ...
EndScan

Begin Transaction
 Select Ar
 If !TableUpdate()
  Rollback
  Return
 EndIf

 Select Gl
 If !TableUpdate()
  Rollback
  Return
 EndIf

 Select InvHeader
 If !TableUpdate()
  Rollback
  Return
 EndIf

** everything is ok the commit
End Transaction
Return

Should I do this posting procedure in the server using plpgsql? Or a combination of Foxpro code and SqlExec() statements? Are there any better ways to accomplish this?

Thanks.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Yes, you should use transactions. In this case the most sensitive thing is id of invoice header. If you use

INSERT INTO invoice_header_table VALUES (..) RETURNING id;

you have unique id of invoice header.

I am not sure if it was your point actually but I hope this information will be usefull.

over 4 years ago · Santiago Trujillo Relatório
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