Explain your strategy for database consistency in a highly concurrent environment.
Write a PostgreSQL query that audits stored account balances against their posted ledger entries. Treat credits as positive, debits as negative, ignore non-posted entries, and safely handle NULL amounts.
account_id, currency, opening_balance, current_balance, expected_balance, and difference.account_id ascending.| Column | Type | Description |
|---|---|---|
| account_idPK | INT | Unique account identifier |
| currency | VARCHAR(3) | ISO currency code |
| opening_balance | NUMERIC(18,2) | Balance before ledger activity |
| current_balance | NUMERIC(18,2) | Stored current account balance |
| Column | Type | Description |
|---|---|---|
| entry_idPK | INT | Unique ledger entry identifier |
| account_id | INT | Account affected by the entry |
| entry_type | VARCHAR(30) | Ledger event type |
| amount | NUMERIC(18,2) | Monetary amount of the entry |
| status | VARCHAR(20) | Processing status of the entry |