improve setval id if remove all rows

This commit is contained in:
Mathieu Jaumotte 2023-03-10 16:18:51 +01:00
parent 307cfcbe74
commit 0ab77b77ed

View File

@ -322,30 +322,30 @@ WHERE household_composition_type1 IS NOT NULL ;
-- Undo 46.
DELETE FROM chill_person_household_composition c USING import.personnes ip WHERE c.household_id = ip.person_id;
SELECT setval('chill_person_household_composition_id_seq', (SELECT max(id) FROM chill_person_household_composition));
SELECT setval('chill_person_household_composition_id_seq', (SELECT COALESCE(max(id),1) FROM chill_person_household_composition));
-- Undo 45.
DELETE FROM chill_person_household_to_addresses hhaddr USING import.personnes ip WHERE hhaddr.household_id = ip.person_id ;
DELETE FROM chill_person_household_to_addresses hhaddr USING import.personnes ip WHERE hhaddr.household_id = ip.person_id;
-- Undo 44.
DELETE FROM chill_person_household_members memb USING import.personnes ip WHERE memb.person_id = ip.person_id;
SELECT setval('chill_person_household_members_id_seq', (SELECT max(id) FROM chill_person_household_members));
SELECT setval('chill_person_household_members_id_seq', (SELECT COALESCE(max(id),1) FROM chill_person_household_members));
DELETE FROM chill_person_household hh USING import.personnes ip WHERE hh.id = ip.person_id;
SELECT setval('chill_person_household_id_seq', (SELECT max(id) FROM chill_person_household));
SELECT setval('chill_person_household_id_seq', (SELECT COALESCE(max(id),1) FROM chill_person_household));
-- Undo 43.
DELETE FROM chill_main_address addr USING import.personnes ip WHERE addr.id = ip.address_id;
SELECT setval('chill_main_address_id_seq', (SELECT max(id) FROM chill_main_address));
SELECT setval('chill_main_address_id_seq', (SELECT COALESCE(max(id),1) FROM chill_main_address));
ALTER TABLE import.personnes DROP column postcode_id;
ALTER TABLE import.personnes DROP column address_id;
-- Undo 42.
DELETE FROM chill_person_person_center_history hist USING import.personnes ip WHERE hist.person_id = ip.person_id;
SELECT setval('chill_person_person_center_history_id_seq', (SELECT max(id) FROM chill_person_person_center_history));
SELECT setval('chill_person_person_center_history_id_seq', (SELECT COALESCE(max(id),1) FROM chill_person_person_center_history));
-- Undo 41.
DELETE FROM chill_person_person p USING import.personnes ip WHERE p.id = ip.person_id;
SELECT setval('chill_person_person_id_seq', (SELECT max(id) FROM chill_person_person));
SELECT setval('chill_person_person_id_seq', (SELECT COALESCE(max(id),1) FROM chill_person_person));
-- Undo 40.
ALTER TABLE import.personnes DROP COLUMN person_id;