From 0ab77b77edd6199fc390d370d385415e83f366e8 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Fri, 10 Mar 2023 16:18:51 +0100 Subject: [PATCH] improve setval id if remove all rows --- sql/import.sql | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/sql/import.sql b/sql/import.sql index 96e13e0..213ca4e 100644 --- a/sql/import.sql +++ b/sql/import.sql @@ -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;