Answer the question
In order to leave comments, you need to log in
How to create an UPDATE trigger without recursion in Postgres?
Hello!
In general procedure and trigger
CREATE FUNCTION advs__up_is_paid_mode() RETURNS TRIGGER
AS $$
BEGIN
IF NEW.balance<NEW.amount THEN
UPDATE advs SET is_paid_mode=0 WHERE id=NEW.id;
ELSE
UPDATE advs SET is_paid_mode=1 WHERE id=NEW.id;
END IF;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER advs__up_is_paid_mode__trigger
AFTER INSERT OR UPDATE
ON advs
FOR EACH ROW
EXECUTE PROCEDURE advs__up_is_paid_mode();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question