copy to temp table method for updating addressbase
This example demonstrates a PostgreSQL method for efficiently replacing the contents of a large AddressBase database table by loading incoming CSV data into temporary tables, building indexes and constraints there, and then using a transactional rename swap to minimize downtime. The script first copies data from `addressbase_cleaned.csv` and `uprn-to-councils.csv` into empty temp tables, then adds primary keys, GiST spatial indexes on `location`, and B-tree indexes on `postcode` and `uprn`. Within a `BEGIN`/`COMMIT` block, it drops foreign keys, renames the existing tables to `_old`, promotes the temp tables to the main names, and re-adds the foreign key constraints. Timings for each operation illustrate the relative cost of loading, indexing, and swapping.