Skip to content

Commit

Permalink
Use tmp_bib_noms_copy for deleting cd_nom except for lists
Browse files Browse the repository at this point in the history
  • Loading branch information
amandine-sahl committed Mar 7, 2022
1 parent 0345b55 commit 4652da6
Showing 1 changed file with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ WHERE cd_nom IN (
FROM taxonomie.taxref t
LEFT OUTER JOIN taxonomie.import_taxref it
ON it.cd_nom = t.cd_nom
WHERE it.cd_nom IS NULL
LEFT OUTER JOIN taxonomie.tmp_bib_noms_copy tbnc
ON tbnc.cd_nom = t.cd_nom
WHERE it.cd_nom IS NULL AND tbnc.deleted IS DISTINCT FROM FALSE
);


Expand Down Expand Up @@ -115,7 +117,13 @@ WHERE tmp_id IN (

-- supression dans les cas ou il n'y a pas de taxons de remplacements
DELETE FROM taxonomie.cor_nom_liste
WHERE id_nom IN (SELECT id_nom FROM taxonomie.tmp_bib_noms_copy WHERE deleted=true);
WHERE id_nom IN (
SELECT id_nom
FROM taxonomie.bib_noms bn
LEFT OUTER JOIN taxonomie.import_taxref it
ON bn.cd_nom = it.cd_nom
WHERE it.cd_nom IS NULL
);

-- Restauration de la clé primaire de cor_nom_liste
ALTER TABLE taxonomie.cor_nom_liste
Expand Down Expand Up @@ -143,11 +151,13 @@ WHERE n.cd_nom = t.cd_nom;

-- Suppression des cd_nom disparus
DELETE FROM taxonomie.bib_noms WHERE cd_nom IN (
SELECT n.cd_nom
FROM taxonomie.bib_noms n
LEFT OUTER JOIN taxonomie.taxref t
ON n.cd_nom = t.cd_nom
WHERE t.cd_nom IS NULL
SELECT t.cd_nom
FROM taxonomie.taxref t
LEFT OUTER JOIN taxonomie.import_taxref it
ON it.cd_nom = t.cd_nom
LEFT OUTER JOIN taxonomie.tmp_bib_noms_copy tbnc
ON tbnc.cd_nom = t.cd_nom
WHERE it.cd_nom IS NULL AND tbnc.deleted IS DISTINCT FROM FALSE
);


Expand All @@ -163,6 +173,15 @@ ON f_cd_ref = t.cd_nom
WHERE n.cd_nom IS NULL;


------------- Cas avec cd_nom de remplacement ????
-- Ajout du cd_nom de remplacement quand il n'existait pas dans bib_noms
-- INSERT INTO taxonomie.tmp_bib_noms_copy(cd_nom, cd_ref, nom_francais, tmp_import)
-- SELECT d.cd_nom_remplacement, n.cd_ref, n.nom_francais, true
-- FROM taxonomie.tmp_bib_noms_copy n
-- JOIN taxonomie.cdnom_disparu d ON n.cd_nom = d.cd_nom
-- WHERE NOT n.cd_nom_remplacement IS NULL
-- ON CONFLICT DO NOTHING;


---- #################################################################################
---- #################################################################################
Expand Down

0 comments on commit 4652da6

Please sign in to comment.