CREATE FUNCTION cen_insertion_point_flore() RETURNS integer AS $_$ DECLARE myrec RECORD; var_gid bigint; var_protocole bigint; var_id_lot_donnee character varying(50); BEGIN FOR myrec IN SELECT gid, protocole, id_lot FROM point_flore_a_importer WHERE id_entite IS NULL LOOP var_gid:=myrec.gid; var_protocole:=myrec.protocole; -- dans la table ese var_id_lot_donnee:=myrec.id_lot; -- a ventiler dans les métadonnées EXECUTE $req$ INSERT INTO entite_spatiale_ecologique (id_entite, id_protocole, validateur_code_personne, validateur_id_structure, id_lot, type_entite, date_creation) VALUES(nextval('entite_spatiale_ecologique_id_entite_seq'),$req$||quote_literal(var_protocole)||$req$, null, null, $req$||quote_literal(var_id_lot_donnee)||$req$, 'point_flore', current_date) $req$; RAISE INFO 'nouvelle ESE de type point_flore ajoutée'; EXECUTE $req$ UPDATE point_flore_a_importer SET id_entite=currval('entite_spatiale_ecologique_id_entite_seq'), date_ventilation=current_date WHERE gid=$req$||quote_literal(var_gid)||$req$ $req$; RAISE INFO 'ligne courante de la table point_flore_a_importer mise à jour'; EXECUTE $req$ INSERT INTO point_flore(id_entite, strate, effectif, effectif_min, effectif_max, type_effectif, coord_x, coord_y, coord_z, systeme_coordonnees, id_taxon, id_releve, descriptif_milieu, "precision", remarque, geometrie, transmis_cbnmp, taxon_mentionne, date_obs, date_debut_obs, date_fin_obs, date_textuelle, phenologie) SELECT id_entite, strate, effectif, effectif_min, effectif_max, type_effectif, coord_x, coord_y, altitude, syst_coord, id_taxon_ref, id_releve, descriptif_milieu, "precision", remarque, geometrie, transmis_cbnmp, taxon_mentionne, date_obs, debut_obs, fin_obs, date_textuelle, phenologie FROM point_flore_a_importer WHERE gid=$req$||var_gid||$req$ $req$; RAISE INFO 'nouveau point_flore ajouté'; EXECUTE $req$ SELECT cen_attribution_personne_auteur_point_flore(id_entite) from point_flore_a_importer WHERE gid=$req$||quote_literal(var_gid)||$req$ $req$; RAISE INFO 'auteur(s) attribué(s)'; EXECUTE $req$ INSERT INTO structure_est_auteur_donnee(id_entite, id_structure, ordre) SELECT id_entite, auteur_id_structure, 1 from point_flore_a_importer WHERE gid=$req$||quote_literal(var_gid)||$req$ $req$; RAISE INFO 'structure auteur attribuée'; END LOOP; RETURN 1; END; $_$ LANGUAGE plpgsql; ALTER FUNCTION public.cen_insertion_point_flore() OWNER TO dba;