Message posté par : Andasolo (josedelcarmenchocoj(a)yahoo.es)
----------------------------------------
Bonjour,
je souhaite insérer des données depuis une table "cana" (couche SIG contenant
les collecteurs du réseau d'assainissement, que j'utilise avec QGIS et Lizmap)
vers une table "anomalies" sans géométrie, le tout en utilisant PostgreSQL v17.
pour cela j'ai créée cette fonction:
-----------------
Code :
CREATE OR REPLACE FUNCTION f_anomalie_cana()
RETURNS trigger
LANGUAGE 'plpgsql'
COST 100
VOLATILE NOT LEAKPROOF
AS $BODY$
BEGIN
INSERT INTO
anomalies(id_objet,type_objet,type_anomalie,date,heure,anomalie)
select tt.objectid,
(select
t.table_name
from information_schema.tables t
inner join information_schema.columns c on c.table_name = t.table_name and
c.table_schema = t.table_schema
where c.column_name = 'anomalie' and t.table_name ='cana'),
case
when tt.anomalie=1 then 'effondrement'
when tt.anomalie=2 then 'racines'
when tt.anomalie=3 then 'fissures'
when tt.anomalie=6 then 'réparée'
when tt.anomalie=7 then 'déplacements d''assemblage'
when tt.anomalie=8 then 'depot'
when tt.anomalie=9 then 'sable'
when tt.anomalie=10 then 'eau stagnante'
when tt.anomalie=11 then 'perforation'
when tt.anomalie=12 then 'eau claire parasite'
when tt.anomalie=17 then 'poinconnement'
when tt.anomalie=18 then 'curage'
else null
end,
current_date,
current_time,
tt.anomalie
from cana tt where tt.anomalie = new.anomalie;
RETURN new;
END;
$BODY$;
et le trigger:
CREATE OR REPLACE TRIGGER trg_anomalie_cana
AFTER INSERT OR UPDATE
ON cana
FOR EACH ROW
EXECUTE FUNCTION f_anomalie_cana();
-----------------
mon problème survient au moment d’insérer des valeurs dans la table "anomalies",
puisque la fonction me duplique des valeurs déjà existantes:
objectid,type_objet,id_objet,anomalie,type_anomalie,update_origine,heure,date
51,cana,15382,2,racines,sigadmin,15:32:33.874172+01,2025/01/24
52,cana,31982,2,racines,sigadmin,15:32:33.874172+01,2025/01/24
53,cana,15382,1,effondrement,sigadmin,16:00:10.671524+01,2025/01/24
54,cana,15382,1,effondrement,sigadmin,16:00:22.865349+01,2025/01/24
55,cana,31982,1,effondrement,sigadmin,16:00:22.865349+01,2025/01/24
56,cana,15386,2,racines,sigadmin,"08:53:38.306502+01",2025/01/27
57,cana,15387,2,racines,sigadmin,"08:53:59.924655+01",2025/01/27
58,cana,15386,2,racines,sigadmin,"08:53:59.924655+01",2025/01/27
en vous remerciant par avance de toute votre aide possible (-:
----------------------------------------
Le message est situé
https://georezo.net/forum/viewtopic.php?pid=371402#p371402
Pour y répondre : geobd(a)ml.georezo.net ou reply de votre messagerie
Pour vous désabonner connectez-vous sur le forum puis Profil / Abonnement
--
Association GeoRezo - le portail géomatique
https://georezo.net