'DELETE from another table with trigger/trigger function
Trying to use trigger to delete a row from a table when a column with the same value is delete from the original table
CREATE OR REPLACE FUNCTION testFunc()
RETURNS trigger AS
$func$
BEGIN
DELETE FROM emergencyinfo
USING massacts
WHERE emergencyinfo.actid = massacts.id;
RETURN NEW;
END
$func$ LANGUAGE plpgsql;
Trigger;
CREATE TRIGGER test_trigger3
AFTER DELETE ON massacts
FOR EACH ROW EXECUTE PROCEDURE testFunc();
This does not work, when i execute query 'delete from massacts where id=5', the row deletes from massacts but the row that holds actid=5 in emergencyinfo does not delete.
However, when i try this trigger by updating a row's id to 5 in massacts table, the row in emergencyinfo with actid=5 does delete.
CREATE TRIGGER test_trigger3
AFTER UPDATE ON massacts
FOR EACH ROW EXECUTE PROCEDURE testFunc();
I have tried to use BEFORE DELETE instead of AFTER, same issue persisted.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
