| 1 | -- The opening balance of the shop's statement for October, and its first page, |
| 2 | -- exactly as the wallet asks for them, for the wallet in :wallet. |
| 3 | EXPLAIN (ANALYZE, BUFFERS, COSTS OFF) |
| 4 | SELECT coalesce(sum(CASE WHEN e.direction = a.normal_balance THEN e.amount ELSE -e.amount END), 0) |
| 5 | FROM entries e JOIN accounts a ON a.id = e.account_id |
| 6 | WHERE e.account_id = :'wallet' AND e.created_at < '2026-10-01'; |
| 7 | |
| 8 | EXPLAIN (ANALYZE, BUFFERS, COSTS OFF) |
| 9 | SELECT e.id, e.created_at, e.transaction_id, t.description, e.direction, e.amount |
| 10 | FROM entries e JOIN transactions t ON t.id = e.transaction_id |
| 11 | WHERE e.account_id = :'wallet' |
| 12 | AND (e.created_at, e.id) > ('2026-10-01', 0) AND e.created_at < '2026-11-01' |
| 13 | ORDER BY e.created_at, e.id |
| 14 | LIMIT 500; |