CREATE OR REPLACE FUNCTION inpn.taxons_fils(character varying)
RETURNS SETOF character varying AS
$BODY$
DECLARE
var_cd_nom alias FOR $1;
BEGIN
RETURN QUERY
WITH RECURSIVE genealogie AS(
SELECT cd_nom, cd_taxsup, lb_nom FROM inpn.taxref WHERE cd_nom=lower(var_cd_nom)
UNION
SELECT inpn.taxref.cd_nom, inpn.taxref.cd_taxsup, inpn.taxref.lb_nom FROM inpn.taxref JOIN genealogie ON inpn.taxref.cd_taxsup = genealogie.cd_nom
)
SELECT cd_nom FROM genealogie;
END;
$BODY$
LANGUAGE plpgsql VOLATILE SECURITY DEFINER
COST 100;
ALTER FUNCTION inpn.taxons_fils(character varying) OWNER TO dba;
Exemple : lister tous les odonates
SELECT inpn.taxons_fils('185356');