Answer the question
In order to leave comments, you need to log in
Where does the infinite loop come from?
trigger function
CREATE OR REPLACE FUNCTION delete_abonent() RETURNS TRIGGER AS $$ BEGIN
IF OLD.bilet_number IN (SELECT bilet_number FROM all_lends) THEN
RAISE EXCEPTION 'У этого абонента есть выданные книги!'; RETURN NULL; END IF;
DELETE FROM all_users WHERE user_login = OLD.user_login;
EXECUTE format('DROP USER %I', OLD.user_login);
DELETE FROM all_abonents WHERE bilet_number = OLD.bilet_number;
END; $$ LANGUAGE plpgsql;
CREATE TRIGGER before_delete_abonent INSTEAD OF DELETE ON all_abonents
FOR EACH ROW EXECUTE PROCEDURE delete_abonent();
DELETE FROM all_abonents WHERE bilet_number = OLD.bilet_number;
Answer the question
In order to leave comments, you need to log in
Let's you better tell why you think that there is no recursion here.
You doing
INSTEAD OF DELETE ON all_subscribers
Why the recursion is understandable - you call DELETE in an INSTEAD OF trigger on DELETE.
Another question is what do you want to do. If you upon successful verification
IF OLD.bilet_number IN (SELECT bilet_number FROM all_lends)
want to delete this subscriber (and only him), then you had to do a regular non-INSTEAD) trigger and instead of the DELETE statement at the end, do RETURN OLD
.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question