 --correspond bien à la phénologie valide définie par le profil du taxon en question
 --La fonction renvoie 'false' pour les données trop imprécises (durée d'observation supérieure à 
 -- la précision temporelle définie dans les paramètres des profils).
-  DECLARE 
-   valid_count integer;
   BEGIN
-  	valid_count:= 
-  		(WITH myphenology AS (
+  	IF EXISTS(
+		WITH myphenology AS (
   			SELECT DISTINCT
 				t.cd_ref AS cd_ref,
 				unnest(

			CASE 
				WHEN p.active_life_stage=true THEN s.id_nomenclature_life_stage 
				ELSE NULL 
			END
			,id_altitude_range)

	SELECT max(ctp.count_valid_data)
	FROM gn_profiles.vm_cor_taxon_phenology ctp, myphenology
	WHERE ctp.cd_ref=myphenology.cd_ref
	AND ctp.period=myphenology.period
	AND (ctp.id_nomenclature_life_stage=myphenology.id_nomenclature_life_stage 
	OR (ctp.id_nomenclature_life_stage IS NULL AND myphenology.id_nomenclature_life_stage IS NULL))
	AND ctp.id_altitude_range=myphenology.id_altitude_range);

	IF valid_count>=(
		SELECT value::integer 
		FROM gn_profiles.t_parameters 
		WHERE name='min_occurrence_check_profile_phenology'
	)
	THEN 
		RETURN true;
	ELSE 
		RETURN false;
    END IF;
  END;
$function$

	)
GROUP BY t.cd_ref;

CREATE MATERIALIZED VIEW gn_profiles.vm_cor_taxon_phenology AS 
WITH classified_data AS (
SELECT DISTINCT
	t.cd_ref AS cd_ref,
	unnest(
