/*EXAMPLE OF A UPDATE FUNCTION WITH TRIGGER PLPGSQL*/
CREATE OR REPLACE FUNCTION update_aumentarpreco ()
RETURNS TRIGGER
LANGUAGE PLPGSQL
AS
$BODY$
BEGIN
IF OLD.ps_availqty = 2 THEN
RETURN NULL;
END IF;
IF NEW.ps_availqty = 2 THEN
NEW.ps_supplycost = OLD.ps_supplycost * 0.10;
RETURN NEW;
END IF;
RETURN NEW;
END;
$BODY$
CREATE TRIGGER update_aumentarpreco
BEFORE UPDATE OF ps_availqty ON partsupp
FOR EACH ROW
EXECUTE PROCEDURE update_aumentarpreco ();
/*DROP TRIGGER update_aumentarpreco ON partsupp*/
/*Testing
UPDATE
partsupp
SET
ps_availqty = 4
WHERE
ps_suppkey = 2*/