1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
CREATE OR REPLACE FUNCTION brain.update_etudiants_id()
RETURNS boolean
LANGUAGE plpgsql
COST 1
AS $function$
DECLARE
v_email_ad varchar;
v_email_perso varchar;
v_annee_academique integer;
v_email_ordre integer;
v_classe varchar;
v_matric_rs integer;
v_numero integer;
v_statut varchar;
v_qualite varchar;
v_groupe varchar;
v_orientation varchar;
v_resultat_final varchar;
v_id_people integer;
BEGIN
FOR v_email_ad, v_email_perso, v_annee_academique, v_email_ordre, v_classe, v_matric_rs, v_numero, v_statut, v_qualite, v_groupe, v_orientation, v_resultat_final, v_id_people
IN SELECT email_ad, email_perso, annee_academique, email_ordre, classe, matric_rs, numero, statut, qualite, groupe, orientation, resultat_final, id_people
FROM brain.etudiants_update
LOOP
INSERT INTO brain.etudiants (email_ad, email_perso, annee_academique, email_ordre, classe, matric_rs, numero, statut, qualite, groupe, orientation, resultat_final,id_people)
VALUES(v_email_ad, v_email_perso, v_annee_academique, v_email_ordre, v_classe, v_matric_rs, v_numero, v_statut, v_qualite, v_groupe, v_orientation, v_resultat_final, v_id_people)
ON CONFLICT ON CONSTRAINT update_id_student DO UPDATE SET
email_ad = excluded.email_ad,
email_perso = excluded.email_perso,
classe = excluded.classe,
statut = excluded.statut,
qualite = excluded.qualite,
groupe = excluded.groupe,
orientation = excluded.orientation,
resultat_final = excluded.resultat_final,
id_people = excluded.id_people;
END LOOP;
truncate table only brain.etudiants_update restart identity cascade;
return true;
END
$function$
; |
Partager