简体   繁体   中英

Row Not Being Deleted After ON DELETE Trigger Runs

I am working in PostgreSQL 8.4 and have written a trigger function like so:

CREATE OR REPLACE FUNCTION otherschema.order_delete_log_procedure() RETURNS TRIGGER AS
$$
BEGIN
    DELETE FROM otherschema.order_log AS thelog WHERE thelog.log_order_id=OLD.order_id;
    RETURN NULL;
END;
$$ LANGUAGE plpgsql;

CREATE TRIGGER order_deletion_log_trigger BEFORE DELETE ON public.order FOR EACH ROW EXECUTE PROCEDURE
otherschema.order_delete_log_procedure();

My problem is, the trigger fires perfectly (the trigger is deleting the log row), however the row that is supposed to be deleted from the table that is firing the trigger is not getting deleted (the order isn't getting deleted).

If I try to delete the order row manually, it just says that no rows were affected and it gives no error. Any thoughts?

Thanks!

Returning NULL from a BEFORE DELETE trigger aborts the delete operation. You should return old instead, or make it an AFTER DELETE trigger.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM