Halo, i'm new with postgresql, now i have a project to migrate db from mysql to postgresql. i want to make a trigger when i delete a parent data, the child will also deleted. here is the structure description:
table_A (trigger)
- table_B
- table_C
- table_D
- table_B
here is the code that i tried:
CREATE OR REPLACE FUNCTION delete_relation() RETURNS trigger AS
$$
BEGIN
DELETE FROM table_C
USING table_B
WHERE table_C.id = table_B.id_C;
DELETE FROM table_C
USING table_B
WHERE table_D.id = table_B.id_D;
DELETE FROM table_B WHERE table_B.id_A = OLD.id;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER
delete_table_A
AFTER DELETE ON
table_A
FOR EACH ROW EXECUTE PROCEDURE delete_relation();
then, when i execute, it will return this:
Function executed no return statement: 7
ERROR: control reached end of trigger procedure without RETURN
CONTEXT: PL/pgSQL function delete_relation()