Skip to content

Instantly share code, notes, and snippets.

@jbdesbas
Last active October 29, 2020 11:05
Show Gist options
  • Select an option

  • Save jbdesbas/bf695c3c8f965a16696e52c08e0f3f22 to your computer and use it in GitHub Desktop.

Select an option

Save jbdesbas/bf695c3c8f965a16696e52c08e0f3f22 to your computer and use it in GitHub Desktop.
Exemple taxref_tree_parents
--Selection des occurences d'Odonates [185356] et taxons inférieurs
--A utiliser également pour sélectionner des espèces, afin d'inclure les éventuelles sous-espèces
SELECT s.*
FROM gn_synthese.synthese s
JOIN taxonomie.taxref t USING (cd_nom)
JOIN taxonomie.taxref_tree_parents ttp ON ttp.cd_nom_parent = t.cd_ref
WHERE ttp.cd_nom_parent = 185356
--Exemple 2 : Liste des parents sous format JSON
SELECT t.lb_nom, t.cd_nom, jsonb_object_agg(t2.id_rang, t2.lb_nom) AS parents
FROM taxonomie.taxref t
JOIN taxonomie.taxref_tree_parents ttp ON ttp.cd_nom = t.cd_ref
JOIN taxonomie.taxref t2 ON t2.cd_nom = ttp.cd_nom_parent
GROUP BY t.cd_nom ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment