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

138
Views
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 answers
Answer question

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 Report
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!