CREATE OR REPLACE RULE delete_v_traitement AS ON DELETE TO s_anc.v_traitement DO INSTEAD DELETE FROM s_anc.traitement WHERE traitement.id_traitement = old.id_traitement;
CREATE OR REPLACE RULE insert_v_traitement AS ON INSERT TO s_anc.v_traitement DO INSTEAD INSERT INTO s_anc.traitement (id_traitement, id_controle, tra_type, tra_nb, tra_long, tra_larg, tra_tot_lin, tra_surf, tra_largeur, tra_hauteur, tra_profondeur, tra_dist_hab, tra_dist_lim_parc, tra_dist_veget, tra_dist_puit, tra_vm_racine, tra_vm_humidite, tra_vm_imper, tra_vm_geogrille, tra_vm_grav_qual, tra_vm_grav_ep, tra_vm_geo_text, tra_vm_ht_terre_veget, tra_vm_tuy_perf, tra_vm_bon_mat, tra_vm_sab_ep, tra_vm_sab_qual, tra_regrep_mat, tra_regrep_affl, tra_regrep_equi, tra_regrep_perf, tra_regbl_mat, tra_regbl_affl, tra_regbl_hz, tra_regbl_epand, tra_regbl_perf, tra_regcol_mat, tra_regcol_affl, tra_regcol_hz, maj, maj_date, "create", create_date, photos_f, fiche_f, schema_f, documents_f, plan_f, tra_longueur, tra_profond, tra_commentaire) VALUES (new.id_traitement, new.id_controle, new.tra_type, new.tra_nb, new.tra_long, new.tra_larg, new.tra_tot_lin, new.tra_surf, new.tra_largeur, new.tra_hauteur, new.tra_profondeur, new.tra_dist_hab, new.tra_dist_lim_parc, new.tra_dist_veget, new.tra_dist_puit, new.tra_vm_racine, new.tra_vm_humidite, new.tra_vm_imper, new.tra_vm_geogrille, new.tra_vm_grav_qual, new.tra_vm_grav_ep, new.tra_vm_geo_text, new.tra_vm_ht_terre_veget, new.tra_vm_tuy_perf, new.tra_vm_bon_mat, new.tra_vm_sab_ep, new.tra_vm_sab_qual, new.tra_regrep_mat, new.tra_regrep_affl, new.tra_regrep_equi, new.tra_regrep_perf, new.tra_regbl_mat, new.tra_regbl_affl, new.tra_regbl_hz, new.tra_regbl_epand, new.tra_regbl_perf, new.tra_regcol_mat, new.tra_regcol_affl, new.tra_regcol_hz, new.maj, new.maj_date, new."create", new.create_date, new.photos_f, new.fiche_f, new.schema_f, new.documents_f, new.plan_f, new.tra_longueur, new.tra_profond, new.tra_commentaire) RETURNING traitement.id_traitement,traitement.id_controle,traitement.tra_type,traitement.tra_nb,traitement.tra_long,traitement.tra_larg,traitement.tra_tot_lin,traitement.tra_surf,traitement.tra_largeur,traitement.tra_hauteur,traitement.tra_profondeur,traitement.tra_dist_hab,traitement.tra_dist_lim_parc,traitement.tra_dist_veget,traitement.tra_dist_puit,traitement.tra_vm_racine,traitement.tra_vm_humidite,traitement.tra_vm_imper,traitement.tra_vm_geogrille,traitement.tra_vm_grav_qual,traitement.tra_vm_grav_ep,traitement.tra_vm_geo_text,traitement.tra_vm_ht_terre_veget,traitement.tra_vm_tuy_perf,traitement.tra_vm_bon_mat,traitement.tra_vm_sab_ep,traitement.tra_vm_sab_qual,traitement.tra_regrep_mat,traitement.tra_regrep_affl,traitement.tra_regrep_equi,traitement.tra_regrep_perf,traitement.tra_regbl_mat,traitement.tra_regbl_affl,traitement.tra_regbl_hz,traitement.tra_regbl_epand,traitement.tra_regbl_perf,traitement.tra_regcol_mat,traitement.tra_regcol_affl,traitement.tra_regcol_hz,traitement.maj,traitement.maj_date,traitement."create",traitement.create_date,traitement.photos_f,traitement.fiche_f,traitement.schema_f,traitement.documents_f,traitement.plan_f, ( SELECT controle.id_installation FROM s_anc.controle WHERE traitement.id_controle = controle.id_controle) AS id_installation, ( SELECT controle.controle_type FROM s_anc.controle WHERE traitement.id_controle = controle.id_controle) AS controle_type, ( SELECT (installation.id_com::text || '_anc_'::text) || installation.id_installation AS num_dossier FROM s_anc.installation WHERE installation.id_com::text ~ similar_escape(( SELECT "user".restriction FROM s_vitis."user" WHERE "user".login::name = "current_user"()), NULL::text) AND installation.id_installation = installation.id_installation) AS num_dossier,traitement.tra_longueur,traitement.tra_profond,traitement.tra_commentaire;