ALTER TRIGGER

Function

ALTER TRIGGER modifies the definition of a trigger.

Precautions

Only the owner of a table where a trigger is created and system administrators can run the ALTER TRIGGER statement.

Syntax

1
ALTER TRIGGER trigger_name ON table_name RENAME TO new_name;

Parameter Description

Example

Create a source table and a trigger table:

1
2
3
4
5
DROP TABLE IF EXISTS test_trigger_src_tbl;
DROP TABLE IF EXISTS test_trigger_des_tbl;

CREATE TABLE test_trigger_src_tbl(id1 INT, id2 INT, id3 INT);
CREATE TABLE test_trigger_des_tbl(id1 INT, id2 INT, id3 INT);

Create the trigger function tri_insert_func():

1
2
3
4
5
6
7
8
9
DROP FUNCTION IF EXISTS tri_insert_func;
CREATE OR REPLACE FUNCTION tri_insert_func() RETURNS TRIGGER AS
           $$
           DECLARE
           BEGIN
                   INSERT INTO test_trigger_des_tbl VALUES(NEW.id1, NEW.id2, NEW.id3);
                   RETURN NEW;
           END
           $$ LANGUAGE PLPGSQL;

Create an INSERT trigger:

1
2
3
4
CREATE TRIGGER insert_trigger
           BEFORE INSERT ON test_trigger_src_tbl
           FOR EACH ROW
           EXECUTE PROCEDURE tri_insert_func();

Modified the trigger delete_trigger.

1
ALTER TRIGGER insert_trigger ON test_trigger_src_tbl RENAME TO insert_trigger_renamed;

Disable the trigger insert_trigger.

1
ALTER TABLE test_trigger_src_tbl DISABLE TRIGGER insert_trigger_renamed;  

Disable all triggers on the test_trigger_src_tbl table.

1
ALTER TABLE test_trigger_src_tbl DISABLE TRIGGER ALL; 

Helpful Links

CREATE TRIGGER, DROP TRIGGER, ALTER TABLE