I have created this trigger:
x
CREATE TRIGGER trig_update
AFTER INSERT
ON "delivery" FOR EACH ROW
EXECUTE PROCEDURE premium1();
With this function:
CREATE OR REPLACE FUNCTION premium1()
RETURNS trigger AS $$
BEGIN
IF (TG_OP='INSERT') THEN
IF(select sum(amount) from delivery where cli_num=OLD.cli_num group by cli_num) > 500.00 THEN
UPDATE client SET Type ='Gold' WHERE cli_num=OLD.cli_num;
END IF;
END IF;
RETURN NULL;
END;
$$LANGUAGE plpgsql;
When inserting a new value in table delivery I’m getting the below error:
ERROR: record “old” is not assigned yet Stan SQL:55000
Any help on this?
Advertisement
Answer
CREATE OR REPLACE FUNCTION premium1()
RETURNS trigger AS $$
BEGIN
IF (TG_OP='INSERT') THEN
IF(select sum(amount) from delivery where cli_num=NEW.cli_num group by cli_num) > 500.00 THEN
UPDATE client SET Type ='Gold' WHERE cli_num=NEW.cli_num;
END IF;
END IF;
RETURN NULL;
END;
$$LANGUAGE plpgsql;