par
okayassu » 13 juin 2014, 13:58
Bonjour ,
je dois faire un trigger qui archive de 2 tables différentes avant d'effacer , j'ai donc crée une table pour archiver , mais lorsque que je lance la fonction que j'ai crée pour effacer cela me renvoie une erreur (ma fonction pour effacer fonctionne sans le trigger )
"ERREUR: l'enregistrement « old » n'a pas de champs « numstage »
CONTEXT: instruction SQL « insert into archive values (default,old.nometudiant,old.prenometudiant,old.numstage,old.titrestage,old.objetstage,old.anneescolaire,old.numetudiant,old.regimeetudiant,old.numcontact,old.numprofsuiveur,old.remarques) »
fonction PL/pgsql archivage(), ligne 6 à instruction SQL
instruction SQL « delete from etudiants where numetudiant = numero »
fonction PL/pgsql effacetudiant(character varying), ligne 14 à instruction SQL"
voici ma fonction pour effacer ainsi que mon trigger :
Code : Tout sélectionner
create or replace function effacetudiant(nometud varchar)
returns void as
$$
declare numero int;
begin
perform nometudiant from etudiants where nometudiant=nometud;
if not found then
raise exception 'l''etudiant % n''existe pas',$1;
else
select numetudiant into numero from etudiants
where nometudiant = nometud;
delete from periodes where numstage in
(select numstage from stages where numetudiant = numero);
delete from stages where numetudiant= numero;
delete from etudiants where numetudiant = numero;
raise notice 'l''etudiant % a été effacé',$1;
return ;
end if;
end;
$$
language plpgsql;
Code : Tout sélectionner
create or replace function archivage1() returns trigger as
$$
begin
insert into archive values (default,old.nometudiant,old.prenometudiant,old.numstage,old.titrestage,old.objetstage,old.anneescolaire,old.numetudiant,old.regimeetudiant,old.numcontact,old.numprofsuiveur,old.remarques);
return old;
end;
$$
language plpgsql;
si quelqu'un avait une petite idée
j'ai aussi testé cela et je reçois la même erreur :
Code : Tout sélectionner
create or replace function archivage() returns trigger as
$$
declare
nometud varchar;
prenometud varchar;
numsta integer;
titresta varchar;
objetsta varchar;
anneescol varchar;
numetud integer;
regimeetud varchar;
numconta integer;
numprofsuiv integer;
remarque varchar;
begin
nometud:=old.nometudiant;
select nometudiant into nometud from etudiants where nometudiant=nometud;
prenometud:=old.prenometudiant;
select prenometudiant into prenometud from etudiants where prenometudiant=prenometud;
numsta:=old.numstage;
select numstage into numsta from stages where numstage=numsta;
titresta:=old.titrestage;
select titrestage into titresta from stages where numstage=numsta;
objetsta:=old.objetstage;
select objetstage into objetsta from stages where numstage=numsta;
anneescol:=old.anneescolaire;
select anneescolaire into anneescol from stages where numstage=numsta;
numetud:=old.numetudiant;
select numetudiant into numetud from stages where numstage=numsta;
regimeetud:=old.regimeetudiant;
select regimeetudiant into regimeetud from stages where numstage=numsta;
numconta:=old.numcontact;
select numcontact into numconta from stages where numstage=numsta;
numprofsuiv:=old.numprofsuiveur;
select numprofsuiveur into numprofsuiv from stages where numstage=numsta;
remarque:=old.remarques;
select remarques into remarque from stages where numstage=numsta;
insert into archive values (default,nometud,prenometud,numsta,titresta,objetsta,anneescol,numetud,regimeetud,numconta,numprofsuiv,remarque);
return old;
end;
$$
language plpgsql;
merci d'avance
Bonjour ,
je dois faire un trigger qui archive de 2 tables différentes avant d'effacer , j'ai donc crée une table pour archiver , mais lorsque que je lance la fonction que j'ai crée pour effacer cela me renvoie une erreur (ma fonction pour effacer fonctionne sans le trigger )
"ERREUR: l'enregistrement « old » n'a pas de champs « numstage »
CONTEXT: instruction SQL « insert into archive values (default,old.nometudiant,old.prenometudiant,old.numstage,old.titrestage,old.objetstage,old.anneescolaire,old.numetudiant,old.regimeetudiant,old.numcontact,old.numprofsuiveur,old.remarques) »
fonction PL/pgsql archivage(), ligne 6 à instruction SQL
instruction SQL « delete from etudiants where numetudiant = numero »
fonction PL/pgsql effacetudiant(character varying), ligne 14 à instruction SQL"
voici ma fonction pour effacer ainsi que mon trigger :
[code]create or replace function effacetudiant(nometud varchar)
returns void as
$$
declare numero int;
begin
perform nometudiant from etudiants where nometudiant=nometud;
if not found then
raise exception 'l''etudiant % n''existe pas',$1;
else
select numetudiant into numero from etudiants
where nometudiant = nometud;
delete from periodes where numstage in
(select numstage from stages where numetudiant = numero);
delete from stages where numetudiant= numero;
delete from etudiants where numetudiant = numero;
raise notice 'l''etudiant % a été effacé',$1;
return ;
end if;
end;
$$
language plpgsql; [/code]
[code]create or replace function archivage1() returns trigger as
$$
begin
insert into archive values (default,old.nometudiant,old.prenometudiant,old.numstage,old.titrestage,old.objetstage,old.anneescolaire,old.numetudiant,old.regimeetudiant,old.numcontact,old.numprofsuiveur,old.remarques);
return old;
end;
$$
language plpgsql;[/code]
si quelqu'un avait une petite idée
j'ai aussi testé cela et je reçois la même erreur :
[code]create or replace function archivage() returns trigger as
$$
declare
nometud varchar;
prenometud varchar;
numsta integer;
titresta varchar;
objetsta varchar;
anneescol varchar;
numetud integer;
regimeetud varchar;
numconta integer;
numprofsuiv integer;
remarque varchar;
begin
nometud:=old.nometudiant;
select nometudiant into nometud from etudiants where nometudiant=nometud;
prenometud:=old.prenometudiant;
select prenometudiant into prenometud from etudiants where prenometudiant=prenometud;
numsta:=old.numstage;
select numstage into numsta from stages where numstage=numsta;
titresta:=old.titrestage;
select titrestage into titresta from stages where numstage=numsta;
objetsta:=old.objetstage;
select objetstage into objetsta from stages where numstage=numsta;
anneescol:=old.anneescolaire;
select anneescolaire into anneescol from stages where numstage=numsta;
numetud:=old.numetudiant;
select numetudiant into numetud from stages where numstage=numsta;
regimeetud:=old.regimeetudiant;
select regimeetudiant into regimeetud from stages where numstage=numsta;
numconta:=old.numcontact;
select numcontact into numconta from stages where numstage=numsta;
numprofsuiv:=old.numprofsuiveur;
select numprofsuiveur into numprofsuiv from stages where numstage=numsta;
remarque:=old.remarques;
select remarques into remarque from stages where numstage=numsta;
insert into archive values (default,nometud,prenometud,numsta,titresta,objetsta,anneescol,numetud,regimeetud,numconta,numprofsuiv,remarque);
return old;
end;
$$
language plpgsql;[/code]
merci d'avance