-- 55_temp_tables_etl.sql
-- Banking Pattern Pack — PostgreSQL
-- Purpose: Temp tables for ETL staging.
-- Context: Retail bank example with customers, accounts, transactions, cards, loans.
-- Date: 2025-08-18
-- Notes:
--   * Safe to read; run on a development DB.
--   * Requires: CREATE privileges; some files may need superuser for extensions.
--   * Search path set to 'bank' schema for clarity.

-- Temp table staging for ETL
CREATE TEMP TABLE tmp_payments(acct BIGINT, amt NUMERIC, kind TEXT) ON COMMIT DROP;
INSERT INTO tmp_payments VALUES (1, 100, 'credit');
INSERT INTO bank.transactions(account_id, amount, tx_type, description)
SELECT acct, amt, CASE WHEN amt>=0 THEN 'credit' ELSE 'debit' END, 'ETL load'
FROM tmp_payments;
