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
   | -- Function: insertupdate(int4, date, int4, int4)
 
-- DROP FUNCTION insertupdate(int4, date, int4, int4);
 
CREATE OR REPLACE FUNCTION insertupdate(int4, date, int4, int4)
  RETURNS bool AS
$BODY$
DECLARE
heure ALIAS FOR $1;
jour ALIAS FOR $2;
formateur ALIAS FOR $3;
participant ALIAS FOR $4;
trouve record;
 
BEGIN
 SELECT INTO trouve * FROM registre
  WHERE regjour=jour
  AND idlogin = formateur
  AND idparticipant = participant;
IF NOT FOUND THEN
 INSERT INTO registre (regheure,regjour,idlogin,idparticipant)
 VALUES (heure,jour,formateur,participant);
 RETURN 't';
 
ELSE
 UPDATE registre SET regheure=heure
  WHERE regjour=jour
  AND idlogin = formateur
  AND idparticipant = participant; 
  RETURN 'f';
END IF;
RETURN 't';
END;
$BODY$
  LANGUAGE 'plpgsql' VOLATILE;
ALTER FUNCTION insertupdate(int4, date, int4, int4) OWNER TO postgres;  | 
Partager