I have an existed trigger in a Postgres 9.3 database, which is defined as follows:
CREATE TRIGGER trig
AFTER UPDATE OR DELETE
ON tab2
FOR EACH ROW
EXECUTE PROCEDURE proc3();
I want to change the trigger to be:
AFTER INSERT OR UPDATE OR DELETE
The manual on ALTER TRIGGER
doesn't explain how to do it.
I want to change the trigger without dropping it. Is that possible?
To modify a DML trigger In Object Explorer, connect to an instance of Database Engine and then expand that instance. Expand the database that you want, expand Tables, and then expand the table that contains the trigger that you want to modify. Expand Triggers, right-click the trigger to modify, and then click Modify.
The PostgreSQL ALTER TABLE command is used to add, delete or modify columns in an existing table. You would also use ALTER TABLE command to add and drop various constraints on an existing table.
Sorry, it's not possible to alter a trigger in this way. an OR REPLACE clause does not exists for triggers. However this is rarely a problem because in postgresql DDL statements can be wrapped in a transaction.
BEGIN;
DROP TRIGGER IF EXISTS trig on tab2;
CREATE TRIGGER trig
AFTER INSERT OR UPDATE OR DELETE
ON tab2
FOR EACH ROW
EXECUTE PROCEDURE proc3();
COMMIT;
The upcoming version of PostgreSQL will support CREATE OR REPLACE
syntax:
CREATE OR REPLACE TRIGGER will either create a new trigger, or replace an existing trigger
To replace the current definition of an existing trigger, use CREATE OR REPLACE TRIGGER, specifying the existing trigger's name and parent table. All other properties are replaced.
CREATE OR REPLACE TRIGGER trig
AFTER INSERT OR UPDATE OR DELETE
ON tab2
FOR EACH ROW
EXECUTE PROCEDURE proc3();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With