From 07df6c4292e63e44fa40fe909dfe489ca75adf8d Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Sat, 11 Mar 2023 16:50:11 +0100 Subject: [PATCH] default value for socialissue_id, user_id, scope_id --- sql/import.sql | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/sql/import.sql b/sql/import.sql index 95a7314..2d04063 100644 --- a/sql/import.sql +++ b/sql/import.sql @@ -369,7 +369,11 @@ INSERT INTO chill_person_accompanying_period_location_history (id, period_id, st INSERT INTO chill_person_accompanying_period_social_issues (accompanyingperiod_id, socialissue_id) SELECT DISTINCT ON (t.period_id) t.period_id, - COALESCE(t.enfant_id, t.parent_id, 1) AS socialissue_id -- quid si pas de socialissue ? + COALESCE( + t.enfant_id, + t.parent_id, + 1 -- default value ? + ) AS socialissue_id FROM ( SELECT p.period_id, (SELECT id FROM chill_person_social_issue WHERE title::jsonb->>'fr' = icp.parent1::jsonb->>'fr' AND parent_id IS NULL) AS parent_id, icp.parent1, @@ -381,7 +385,10 @@ FROM ( -- 57. Link referrer to periods UPDATE chill_person_accompanying_period acp - SET user_id = (SELECT id FROM users WHERE users.username = ip.referrer) + SET user_id = COALESCE( + (SELECT id FROM users WHERE users.username = ip.referrer), + 1 -- default value ? + ) FROM import.periodes ip WHERE acp.id = ip.period_id; --SELECT ip.id, (SELECT id FROM users WHERE users.username = ip.referrer) AS referrer_id, ip.referrer, acp.id as period_id, acp.user_id FROM chill_person_accompanying_period acp JOIN import.periodes ip ON ip.period_id = acp.id ORDER BY ip.id; @@ -389,7 +396,7 @@ UPDATE chill_person_accompanying_period acp INSERT INTO accompanying_periods_scopes (accompanying_period_id, scope_id) SELECT ip.period_id, COALESCE( (SELECT id FROM scopes s WHERE ip.acp_scopes1::jsonb->>'fr' = s.name::jsonb->>'fr'), - (SELECT id from scopes s WHERE s.name::jsonb->>'fr' = 'tous') -- default 'tous' + (SELECT id from scopes s WHERE s.name::jsonb->>'fr' = 'tous') -- default value 'tous' ) FROM import.periodes ip; @@ -599,8 +606,6 @@ ALTER TABLE import.periodes DROP COLUMN openingdate1; ALTER TABLE import.periodes DROP COLUMN closingdate1; --- ------------- --- tiers choices_list: civility kind profession category -- ============= -- QUESTIONS