Fix WHERE jsonb comparison

This commit is contained in:
Mathieu Jaumotte 2023-03-10 16:20:58 +01:00
parent 0ab77b77ed
commit e569d77bd2

View File

@ -399,8 +399,8 @@ ALTER TABLE import.personnes DROP COLUMN civility1;
-- Undo 13. -- Undo 13.
DELETE FROM chill_person_social_issue USING import.choix_periodes i DELETE FROM chill_person_social_issue USING import.choix_periodes i
WHERE parent_id IN ( SELECT id FROM chill_person_social_issue cpsi WHERE cpsi.title::jsonb = i.parent1::jsonb AND cpsi.parent_id IS NULL ); WHERE parent_id IN ( SELECT id FROM chill_person_social_issue cpsi WHERE cpsi.title::jsonb->>'fr' = i.parent1::jsonb->>'fr' AND cpsi.parent_id IS NULL );
DELETE FROM chill_person_social_issue cpsi USING import.choix_periodes icp WHERE cpsi.title::jsonb = icp.parent1::jsonb AND cpsi.parent_id IS NULL ; DELETE FROM chill_person_social_issue cpsi USING import.choix_periodes icp WHERE cpsi.title::jsonb->>'fr' = icp.parent1::jsonb->>'fr' AND cpsi.parent_id IS NULL ;
SELECT setval('chill_person_social_issue_id_seq', (SELECT COALESCE(max(id),1) FROM chill_person_social_issue)); SELECT setval('chill_person_social_issue_id_seq', (SELECT COALESCE(max(id),1) FROM chill_person_social_issue));
ALTER TABLE import.choix_periodes DROP COLUMN enfant1; ALTER TABLE import.choix_periodes DROP COLUMN enfant1;
ALTER TABLE import.choix_periodes DROP COLUMN parent1; ALTER TABLE import.choix_periodes DROP COLUMN parent1;
@ -410,46 +410,46 @@ DELETE FROM users USING import.choix_periodes icp WHERE users.username::text = i
SELECT setval('users_id_seq', (SELECT COALESCE(max(id),1) FROM users)); SELECT setval('users_id_seq', (SELECT COALESCE(max(id),1) FROM users));
-- Undo 11. -- Undo 11.
DELETE FROM scopes USING import.choix_periodes icp WHERE scopes.name::jsonb = icp.acp_scopes1::jsonb; DELETE FROM scopes USING import.choix_periodes icp WHERE scopes.name::jsonb->>'fr' = icp.acp_scopes1::jsonb->>'fr';
SELECT setval('scopes_id_seq', (SELECT COALESCE(max(id),1) FROM scopes)); SELECT setval('scopes_id_seq', (SELECT COALESCE(max(id),1) FROM scopes));
ALTER TABLE import.choix_periodes DROP COLUMN acp_scopes1; ALTER TABLE import.choix_periodes DROP COLUMN acp_scopes1;
-- Undo 10. -- Undo 10.
DELETE FROM chill_main_user_job cmuj USING import.choix_periodes icp WHERE cmuj.label::jsonb = icp.job1::jsonb; DELETE FROM chill_main_user_job cmuj USING import.choix_periodes icp WHERE cmuj.label::jsonb->>'fr' = icp.job1::jsonb->>'fr';
SELECT setval('chill_main_user_job_id_seq', (SELECT COALESCE(max(id),1) FROM chill_main_user_job)); SELECT setval('chill_main_user_job_id_seq', (SELECT COALESCE(max(id),1) FROM chill_main_user_job));
ALTER TABLE import.choix_periodes DROP COLUMN job1; ALTER TABLE import.choix_periodes DROP COLUMN job1;
-- Undo 9. -- Undo 9.
DELETE FROM chill_person_accompanying_period_origin cpapo USING import.choix_periodes icp WHERE cpapo.label::jsonb = icp.origin1::jsonb; DELETE FROM chill_person_accompanying_period_origin cpapo USING import.choix_periodes icp WHERE cpapo.label::jsonb->>'fr' = icp.origin1::jsonb->>'fr';
SELECT setval('chill_person_accompanying_period_origin_id_seq', (SELECT COALESCE(max(id),1) FROM chill_person_accompanying_period_origin)); SELECT setval('chill_person_accompanying_period_origin_id_seq', (SELECT COALESCE(max(id),1) FROM chill_person_accompanying_period_origin));
ALTER TABLE import.choix_periodes DROP COLUMN origin1; ALTER TABLE import.choix_periodes DROP COLUMN origin1;
-- Undo 8. -- Undo 8.
DELETE FROM chill_person_accompanying_period_closingmotive cpapcm USING import.choix_periodes icp WHERE cpapcm.name::jsonb = icp.closingmotive1::jsonb; DELETE FROM chill_person_accompanying_period_closingmotive cpapcm USING import.choix_periodes icp WHERE cpapcm.name::jsonb->>'fr' = icp.closingmotive1::jsonb->>'fr';
SELECT setval('chill_person_accompanying_period_closingmotive_id_seq', (SELECT COALESCE(max(id),1) FROM chill_person_accompanying_period_closingmotive)); SELECT setval('chill_person_accompanying_period_closingmotive_id_seq', (SELECT COALESCE(max(id),1) FROM chill_person_accompanying_period_closingmotive));
ALTER TABLE import.choix_periodes DROP COLUMN closingmotive1; ALTER TABLE import.choix_periodes DROP COLUMN closingmotive1;
-- Undo 7. -- Undo 7.
DELETE FROM chill_person_household_position cphp USING import.choix_personnes icp WHERE cphp.label::jsonb = icp.household_position1::jsonb; DELETE FROM chill_person_household_position cphp USING import.choix_personnes icp WHERE cphp.label::jsonb->>'fr' = icp.household_position1::jsonb->>'fr';
SELECT setval('chill_person_household_position_id_seq', (SELECT COALESCE(max(id),1) FROM chill_person_household_position)); SELECT setval('chill_person_household_position_id_seq', (SELECT COALESCE(max(id),1) FROM chill_person_household_position));
ALTER TABLE import.choix_personnes DROP COLUMN household_position1; ALTER TABLE import.choix_personnes DROP COLUMN household_position1;
-- Undo 6. -- Undo 6.
DELETE FROM chill_person_household_composition_type cphct USING import.choix_personnes icp WHERE cphct.label::jsonb = icp.household_composition_type1::jsonb AND cphct.id > 6; DELETE FROM chill_person_household_composition_type cphct USING import.choix_personnes icp WHERE cphct.label::jsonb->>'fr' = icp.household_composition_type1::jsonb->>'fr' AND cphct.id > 6;
SELECT setval('chill_person_household_composition_type_id_seq', (SELECT COALESCE(max(id),1) FROM chill_person_household_composition_type)); SELECT setval('chill_person_household_composition_type_id_seq', (SELECT COALESCE(max(id),1) FROM chill_person_household_composition_type));
ALTER TABLE import.choix_personnes DROP COLUMN household_composition_type1; ALTER TABLE import.choix_personnes DROP COLUMN household_composition_type1;
-- Undo 5. -- Undo 5.
DELETE FROM chill_person_marital_status cpms USING import.choix_personnes icp WHERE cpms.name::jsonb = icp.maritalstatus1::jsonb AND cpms.id <> 'célibat.' AND cpms.id <> 'marié'; -- existing marital status DELETE FROM chill_person_marital_status cpms USING import.choix_personnes icp WHERE cpms.name::jsonb->>'fr' = icp.maritalstatus1::jsonb->>'fr' AND cpms.id <> 'célibat.' AND cpms.id <> 'marié'; -- existing marital status
ALTER TABLE import.choix_personnes DROP COLUMN maritalstatus1; ALTER TABLE import.choix_personnes DROP COLUMN maritalstatus1;
-- Undo 4. -- Undo 4.
DELETE FROM country USING import.choix_personnes icp WHERE country.name::jsonb = icp.country1::jsonb AND country.id > 249; -- 249 existing countries DELETE FROM country USING import.choix_personnes icp WHERE country.name::jsonb->>'fr' = icp.country1::jsonb->>'fr' AND country.id > 249; -- 249 existing countries
SELECT setval('country_id_seq', (SELECT COALESCE(max(id),1) FROM country)); SELECT setval('country_id_seq', (SELECT COALESCE(max(id),1) FROM country));
ALTER TABLE import.choix_personnes DROP COLUMN country1; ALTER TABLE import.choix_personnes DROP COLUMN country1;
-- Undo 3. -- Undo 3.
DELETE FROM chill_main_civility cmc USING import.choix_personnes ip WHERE cmc.name::jsonb = ip.civility1::jsonb; DELETE FROM chill_main_civility cmc USING import.choix_personnes ip WHERE cmc.name::jsonb->>'fr' = ip.civility1::jsonb->>'fr';
SELECT setval('chill_main_civility_id_seq', (SELECT COALESCE(max(id),1) FROM chill_main_civility)); SELECT setval('chill_main_civility_id_seq', (SELECT COALESCE(max(id),1) FROM chill_main_civility));
ALTER TABLE import.choix_personnes DROP COLUMN civility1; ALTER TABLE import.choix_personnes DROP COLUMN civility1;