📅  最后修改于: 2022-03-11 15:05:05.149000             🧑  作者: Mango
--EXAMPLE OF A UPDATE FUNCTION WITH TRIGGER PLPGSQL
CREATE OR REPLACE FUNCTION update_aumentarpreco ()
RETURNS TRIGGER
LANGUAGE PLPGSQL
AS
$BODY$
BEGIN
IF NEW.ps_availqty = 2 THEN
NEW.ps_supplycost = OLD.ps_supplycost * 0.10;
RETURN NEW;
END IF;
RETURN NULL;
END;
$BODY$
CREATE TRIGGER update_aumentarpreco
BEFORE UPDATE OF ps_availqty ON partsupp
FOR EACH ROW
EXECUTE PROCEDURE update_aumentarpreco ();