SELECT DISTINCT ON (histo_bdp_parcelle.gid)
 histo_bdp_parcelle.gid,
 histo_bdp_parcelle.cleparc,
 histo_bdp_parcelle.code_dep,
 histo_bdp_parcelle.code_com,
 histo_bdp_parcelle.nom_com,
 histo_bdp_parcelle.section,
 mf.numr_parcelle,
 histo_bdp_parcelle.annee,
 mf.lieu_dit,
 mf.surface,
 mf.code_site,
 mf.code_acte,
 mf.division,
 mf.def_geo,
 mf.natr_acte,
 mf.maitrise_fonciere,
 mf.duree_conv,
 mf.echeance_prevue,
 histo_bdp_parcelle.geom
INTO mf.mf_37002_BDP_histo_130122
FROM spatial.histo_bdp_parcelle
JOIN ( SELECT mf_generale.cleparc,
			mf_generale.lieu_dit,
			mf_generale.surface,
			mf_generale.code_site,
			mf_generale.code_acte,
			mf_generale.division,
			mf_generale.def_geo,
			mf_generale.numr_parcelle,
			mf_acte.natr_acte,
			mf_acte.maitrise_fonciere,
			mf_acte.duree_conv,
			mf_acte.echeance_prevue
        FROM mf_generale, mf_acte
		WHERE mf_generale.code_acte::text = mf_acte.code_acte::text
		AND mf_generale.code_site::text ~~ '37002%'::text) mf
ON histo_bdp_parcelle.cleparc::text = mf.cleparc::text;
