...
1. Script to update multiple ACTUAL records containing the same generation
Code Block | ||||
---|---|---|---|---|
| ||||
DO $$ BEGIN CREATE TEMP TABLE external_id_max_created_date_table ON COMMIT DROP AS SELECT rl.external_id, MAX(rl.created_date) AS last_creation_date FROM {tenantId}_mod_source_record_storage.records_lb rl, ( SELECT external_id FROM {tenantId}_mod_source_record_storage.records_lb WHERE state = 'ACTUAL' GROUP BY external_id, generation HAVING COUNT(external_id) > 1 ) AS external_id_of_duplicates_with_same_generation WHERE rl.external_id = external_id_of_duplicates_with_same_generation.external_id GROUP by rl.external_id; UPDATE {tenantId}_mod_source_record_storage.records_lb r SET state = 'OLD' FROM external_id_max_created_date_table WHERE r.external_id = external_id_max_created_date_table.external_id AND r.created_date < external_id_max_created_date_table.last_creation_date; END; $$; |
...