1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
CREATE FUNCTION check_symbole_before() RETURNS OPAQUE AS '
DECLARE
symb_curr TEXT;
last_symb_id INTEGER;
last_gid_compt INTEGER;
BEGIN
last_symb_id := (SELECT symb_id FROM symbole ORDER BY symb_id DESC LIMIT 1);
last_gid_compt := (SELECT compt FROM gids ORDER BY compt DESC LIMIT 1);
RAISE WARNING ''Dernier compteur GID: % et dernier symb_id: %'', last_gid_compt, last_symb_id;
SELECT INTO symb_curr symb FROM symbole WHERE symb = NEW.symb;
IF FOUND THEN
UPDATE gids SET symb_id = last_symb_id WHERE compt = last_gid_compt;
RAISE EXCEPTION ''symb_id duplique => table gids mise a jour'';
END IF;
RETURN NEW;
END;
' LANGUAGE 'PLPGSQL';
CREATE TRIGGER symbole_trigger_before BEFORE INSERT
ON symbole
FOR EACH ROW
EXECUTE PROCEDURE check_symbole_before(); |
Partager