使用 repeatable read
回想影片內容,現在動手操作一次 repeatable read 交易。我們想要為允許消費者存款的銀行,替其自有資產設定一個「穩定性」係數。做法是把自訂欄位 FIELD48 設為某個預留值;若該銀行允許消費者開立存款帳戶(由 RCONP752 指示),就設定為該值。
外部交易的干擾會改變我們係數的套用結果。Repeatable read 會保護你的交易,不讓外部來源修改在我們執行交易中第一個查詢時可取得的資料。
本練習屬於課程
PostgreSQL 的交易與錯誤處理
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
-- Create a new transaction with a repeatable read isolation level
___ ___ ___ ___ ___ ___;
-- Update records for banks that allow consumer deposit accounts
UPDATE ffiec_reci
SET FIELD48 = 100
WHERE RCONP752 = 'true';
-- Update records for banks that do not allow consumer deposit accounts
UPDATE ffiec_reci
SET FIELD48 = 50
WHERE RCONP752 = 'false';
-- Commit the transaction
___;