Database Reference
In-Depth Information
DELETE , we can create a single trigger to be called for any of them. So let's replace
the previous three triggers with just the following:
CREATE TRIGGER notify_trigger
AFTER INSERT OR UPDATE OR DELETE
ON notify_test
FOR EACH ROW
EXECUTE PROCEDURE notify_trigger();
The ability to put more than one of INSERT , OR UPDATE , OR DELETE in the same
trigger definition is a PostgreSQL extension to SQL standard. Since the action part
of the trigger definition is non-standard anyway, especially when using a PL/pgSQL
trigger function, this should not be a problem.
Let's now drop the individual triggers truncate the table and test again:
postgres=# DROP TRIGGER notify_insert_trigger
ON notify_test;
DROP TRIGGER
postgres=# DROP TRIGGER notify_update_trigger
ON notify_test;
DROP TRIGGER
postgres=# DROP TRIGGER notify_delete_trigger
ON notify_test;
DROP TRIGGER
postgres=# TRUNCATE notify_test;
TRUNCATE TABLE
postgres=# INSERT INTO notify_test VALUES(1);
NOTICE: Hi, I got notify_trigger invoked FOR
ROW AFTER INSERT on notify_test
INSERT 0 1
Works fine, but this reveals one weakness: we did not get any notification on
TRUNCATE !
Search WWH ::




Custom Search