· 8 years ago · Mar 18, 2018, 02:44 PM
1START TRANSACTION;
2
3DO $$
4BEGIN
5 DROP TABLE IF EXISTS temp_id_uuid_mapping ;
6 CREATE TABLE IF NOT EXISTS temp_id_uuid_mapping (
7 id text,
8 original_id text
9 );
10
11 copy temp_id_uuid_mapping from '/tmp/id_uuid_mapping.bin' with binary;
12
13 CREATE TEMPORARY TABLE IF NOT EXISTS events_vehicle_aggregations_temp
14 AS SELECT * FROM events_vehicle_aggregations;
15
16 UPDATE events_vehicle_aggregations_temp
17 SET vehicle = temp_id_uuid_mapping.id
18 FROM temp_id_uuid_mapping
19 WHERE events_vehicle_aggregations_temp.vehicle = temp_id_uuid_mapping.original_id;
20
21 DELETE FROM events_vehicle_aggregations;
22
23 INSERT INTO events_vehicle_aggregations
24 SELECT * FROM events_vehicle_aggregations_temp;
25
26 DROP TABLE events_vehicle_aggregations_temp;
27
28 EXCEPTION WHEN OTHERS THEN RAISE NOTICE 'Exception during execution - %', SQLERRM ;
29END $$;
30
31COMMIT;