title: Avoid SQL deadlocks on CurrentAccountBalance update
body: <p>I'm evaluating PostgreSQL for some personal project.
  I was inspirited by it's Multi-Version Concurrency Control (MVCC)</p>
  
  <p>I simulated a basic need - insert transaction and perform a vendor balance update with many threads at the same time, running the SQL commands like:</p>
  
  <pre><code>INSERT INTO 
  VendorAccountTransactions (VendorId, BalanceBefore, BalanceAfter) 
  VALUES (
     1, 
     (SELECT CurrentBalance FROM VendorAccounts WHERE VendorId = 1),  
     (SELECT CurrentBalance FROM VendorAccounts WHERE VendorId = 1) + 19.99
  );
  
  UPDATE VendorAccounts SET CurrentBalance = CurrentBalance + 19.99 WHERE VendorId = 1;
  </code></pre>
  
  <p>Any Idea how to avoid deadlocks in such common case?</p>
  
  <p>What is is needed - simply insert the transaction description with "balance before" / "balance after" and update the balance.</p>
  
  <p>It will be used in high load application. 
  How to achieve the right result for this simple business need?</p>
  
  <p>Thank you.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>Maybe there is any other solution to re-design the database to avoid deadlocks or use some other solution to keep the business need solved?</p>